Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: JDBC code not included into JAR file??

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question JDBC code not included into JAR file??

    Hi there, was wondering if anyone could help me.

    I developed an application which works with MySQL using JDBC. It all works fine, but when I try to create a JAR file for my program, the code that uses mySQL seems not to be included into the jar file!

    I added code for displaying messages in different parts of my code to find out at what point the problem is. It looks like the code that goes after line "Statement statement = connection.createStatement();" does not get included into the jar file.

    Here is my main class code:
    import java.sql.*;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
     
    public class ResourceManagementApplication extends JFrame {
    	private static MainFrame mainFrame;
     
    	public static void main(String[] args) {		
               Database db = new Database();		
     
              try {
            	JOptionPane.showMessageDialog(null, "here 1",
    	    			"There was an error!", JOptionPane.ERROR_MESSAGE);	    	
     
            	Connection connection = db.connect("jdbc:mysql://localhost:3306/", "root", "pw");
     
            	JOptionPane.showMessageDialog(null, "here 2",
    	    			"There was an error!", JOptionPane.ERROR_MESSAGE);
     
            	Statement statement = connection.createStatement();
     
    		JOptionPane.showMessageDialog(null, "here 3",
    	    			"There was an error!", JOptionPane.ERROR_MESSAGE);
     
                   statement.executeUpdate("USE ResourceManagementApplication;");
     		JOptionPane.showMessageDialog(null, "here 4",
    	    			"There was an error!", JOptionPane.ERROR_MESSAGE);
     
                   statement.close();
          		mainFrame = new MainFrame(connection);      
            }
            catch( SQLException e ) {
    	    	e.printStackTrace();
    	}
    	catch( Exception e ) {
    	    	e.printStackTrace();
    	}
        }
    }
    If I create and run the jar file, I get error message saying "here 1" and "here 2", but nothing at all happens after that.

    Any ideas why that could be? I really need to get this working!
    Last edited by copeg; December 17th, 2010 at 11:01 AM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: JDBC code not included into JAR file??

    For future reference, please flank you code with the [highlight=java][/highlight] tags. I've edited your post to highlight the java code.

    Any exceptions being thrown? What does the console look like during runtime? My guess is that you are missing the driver on your classpath, which would cause an exception to be thrown and the behavior you see. Package the drive in your jar, or include it on the classpath when you run the jar.

  3. The Following User Says Thank You to copeg For This Useful Post:

    friday (December 17th, 2010)

  4. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JDBC code not included into JAR file??

    oh, sorry, will do next time.

    no, no exceptions as far as I could see.

    that sounds like a very good guess! The problem is - I have no idea how to do it. Could you help or tell me what to google?

  5. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: JDBC code not included into JAR file??

    Quote Originally Posted by friday View Post
    The problem is - I have no idea how to do it. Could you help or tell me what to google?
    Lesson: Packaging Programs in JAR Files (The Java™ Tutorials > Deployment)

  6. The Following User Says Thank You to KevinWorkman For This Useful Post:

    friday (December 17th, 2010)

  7. #5
    Junior Member
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: JDBC code not included into JAR file??

    thanks everyone, it works now!

Similar Threads

  1. Code for parsing .c file in java
    By Kakashi in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: March 6th, 2013, 12:51 AM
  2. JDBC
    By Abdul Rasheed in forum JDBC & Databases
    Replies: 1
    Last Post: August 13th, 2010, 07:01 AM
  3. Help regarding JDBC connectivity in JSP
    By Lovable_Kumar in forum JDBC & Databases
    Replies: 0
    Last Post: May 30th, 2010, 11:53 AM
  4. Help with JDBC
    By michaelmel in forum JDBC & Databases
    Replies: 0
    Last Post: May 14th, 2010, 07:11 AM
  5. why does this code read an html file uncontinuously
    By nasi in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 25th, 2010, 09:09 PM

Tags for this Thread