Results 1 to 2 of 2
- 12-17-2010, 02:54 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 1
- Rep Power
- 0
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!
- 12-17-2010, 07:13 PM #2
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
-
Classes from included jar libraries are not available in Axis 2
By jeremycod in forum Advanced JavaReplies: 0Last Post: 10-31-2010, 08:51 AM -
Included file throws error.
By killerf2006 in forum New To JavaReplies: 3Last Post: 08-20-2010, 11:18 AM -
Sending files though bluetooth (URL included) ???
By agusCba in forum Sun Java Wireless ToolkitReplies: 2Last Post: 04-03-2010, 11:53 PM -
using jdbc from a jar file
By nishant.4545 in forum Advanced JavaReplies: 2Last Post: 08-03-2009, 03:44 AM -
jdbc/ swing code problem
By sami in forum Advanced JavaReplies: 1Last Post: 08-13-2007, 02:26 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks