Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

executable jar can't find mysql-jdbc driver class

843859Aug 10 2006
I've written a program that takes data from some xml files stored on a server and populates a database with the data. I started by developing in Eclipse 3.2.0 on Windows XP Professional using JDOM for parsing the xml and MySQL Connector/J 3.1 for database connectivity.

When installing MySQL Connector/J 3.1 the instructions (linked from dev.mysql.com, http://www.developer.com/java/data/article.php/3417381#Installation_and_Preparation_of_MySQL) mentioned three methods for using the driver. Following the tutorial, I chose the option in which the jar file named mysql-connector-java-3.0.17-ga-bin.jar is copied into the folder named C:\java\j2sdk1.4.2_12\jre\lib\ext. The tutorial claimed that this made it unnecessary to add this jar to the classpath.

I completed and tested the program in Eclipse and was satisfied with the results, so I chose to go to the next step. Using Ant I wanted to create an executable jar that will run my program. I was able to create the executable jar, but it threw the following exception:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at Model.importStats(Unknown Source)
	at Main.main(Unknown Source)
Clearly the JDBC driver class can't be found. Assuming this was because I might have to actually add the jar file to the classpath I went ahead and edited the classpath to include C:\java\j2sdk1.4.2_12\jre\lib\ext\mysql-connector-java-3.0.17-ga-bin.jar. I rebuilt the executable jar and tried again. Same exception thrown.

I then deleted the jar file in C:\java\j2sdk1.4.2_12\jre\lib\ext\ and changed the classpath to use C:\java\mysql-connector-java-3.0.17-ga\mysql-connector-java-3.0.17-ga\mysql-connector-java-3.0.17-ga-bin.jar. I tried again and it failed again.

I returned to working in Eclipse this time without the jar in the classpath or in C:\java\j2sdk1.4.2_12\jre\lib\ext\ and of course it failed once more.

I put the jar back in C:\java\j2sdk1.4.2_12\jre\lib\ext\ and in the classpath. This time I added a line to the build file to copy the jar and paste it in the directory where my executable jar would be run from. I had done this with the JDOM jar, so I was hoping it would work in this case too. But it didn't.

At this point I am completely confused. My Google searches for solutions to this problem have turned up nothing and none of my resource books have any useful information for solving this problem. I was hoping that someone on these forums might have a suggestion for fixing this bug.

Thanks in advance for advice you are able to give me.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 7 2006
Added on Aug 10 2006
0 comments
550 views