wood burning stoves 2.0*
The moose likes JDBC and the fly likes Another  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Another  "com.mysql.jdbc.Driver" Connection problem" Watch "Another  "com.mysql.jdbc.Driver" Connection problem" New topic
Author

Another "com.mysql.jdbc.Driver" Connection problem

Preston Thornton
Ranch Hand

Joined: Jun 24, 2008
Posts: 80
I am using the
tutorial to learn more about the JDBC Drivers. I am getting the following errors:

Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at de.vogella.mysql.first.MySQLAccess.readDataBase(MySQLAccess.java:21)
at de.vogella.mysql.first.test.Main.main(Main.java:8)


The code is



Where the problem is steming from:



Classpath: C:\mysql-connector-java-5.1.15
File: C:\mysql-connector-java-5.1.15\mysql-connector-java-5.1.15-bin.jar

Is there anyway to confirm the URL path within MySQL Workbench? This may be the issue.


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Preston Thornton wrote:Is there anyway to confirm the URL path within MySQL Workbench? This may be the issue.


I don't know the answer to that, but it isn't your problem. This exception:

Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver


means that the driver class can't be found. And that would be because you didn't put the jar containing the driver file into your classpath.

But you're not alone. Probably 10 percent of the questions in this forum are this question. So if the hint about the classpath isn't enough, I'm sure that somebody has explained how to set your classpath in detail, or at least posted a link to the tutorial, in one or more of those threads.
Preston Thornton
Ranch Hand

Joined: Jun 24, 2008
Posts: 80
Yeah, I read about that in the search for similar issues. My classpath is as follows:



This is what is in that directory
mysql-connector-java-5.1.15-bin.jar


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Your classpath is supposed to consist of directories (where Java will look for classes) and jar files (where Java will look for classes). Specify the jar file in your classpath if you want Java to use it (and you do).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Another "com.mysql.jdbc.Driver" Connection problem