XXXconanXXX
Cocktails anyone?
- Reaction score
- 284
I'm beginning to detest JARs. The first time I found the need for one I had an incredibly frustrating time getting it to read my main-class; this time however, the program doesn't connect to my MySQL database when I package the whole thing into a JAR.
I'm using the MySQL Connector/J Driver 5.1.16 to connect to my database. Works fine when ran through JCreator (Akin to Eclipse or NetBeans) but not when I package it into a JAR.
The connect function looks like this:
The Class.forName().newInstance() is what's giving me the headache. It doesn't load the driver even when I have the classpath inside the directory when I JAR it. I've searched and searched for an answer, and the closest I got is to using various plugins to explode JARs inside of the top-level JAR, which I have no clue how to do, considering most of the solutions are on completely foreign technologies.
Anyone have an idea? This is my first time using the JDBC API, and from what I gather Class.forName creates a new class of that Driver, so why doesn't it? I put the file it calls for in there, which calls to a super (Guessing it's the driver files installed in my Java folder) and it simply won't work. Any ideas?
Thanks in advance for the help.
I'm using the MySQL Connector/J Driver 5.1.16 to connect to my database. Works fine when ran through JCreator (Akin to Eclipse or NetBeans) but not when I package it into a JAR.
The connect function looks like this:
Code:
public boolean Connect(JTextArea log) {
con = null;
try {
String url = "jdbc:mysql://localhost:3306/test";
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(url, "root", "");
return true;
} catch(Exception e) {
log.append("Connection Exception: " + e.getMessage() + "\n");
return false;
} finally {
}
}
The Class.forName().newInstance() is what's giving me the headache. It doesn't load the driver even when I have the classpath inside the directory when I JAR it. I've searched and searched for an answer, and the closest I got is to using various plugins to explode JARs inside of the top-level JAR, which I have no clue how to do, considering most of the solutions are on completely foreign technologies.
Anyone have an idea? This is my first time using the JDBC API, and from what I gather Class.forName creates a new class of that Driver, so why doesn't it? I put the file it calls for in there, which calls to a super (Guessing it's the driver files installed in my Java folder) and it simply won't work. Any ideas?
Thanks in advance for the help.