Results 1 to 2 of 2
  1. #1
    friday is offline Member
    Join Date
    Dec 2010
    Posts
    1
    Rep Power
    0

    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!

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    right, your mysql jdbc driver jar file would need to be on the classpath.
    if you are creating an executable jar file then you would need to have the manifest set the classpath to refer to the mysql jdbc jar file as well.

    or if you are using ant to package the jar file, perhaps you could use the zipfileset to have the contents of the mysql jdbc jar file added into your generated jar file so there is only one jar file containing everything that is needed.

Similar Threads

  1. Replies: 0
    Last Post: 10-31-2010, 08:51 AM
  2. Included file throws error.
    By killerf2006 in forum New To Java
    Replies: 3
    Last Post: 08-20-2010, 11:18 AM
  3. Sending files though bluetooth (URL included) ???
    By agusCba in forum Sun Java Wireless Toolkit
    Replies: 2
    Last Post: 04-03-2010, 11:53 PM
  4. using jdbc from a jar file
    By nishant.4545 in forum Advanced Java
    Replies: 2
    Last Post: 08-03-2009, 03:44 AM
  5. jdbc/ swing code problem
    By sami in forum Advanced Java
    Replies: 1
    Last Post: 08-13-2007, 02:26 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •