File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Problem with loading driver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Problem with loading driver" Watch "Problem with loading driver" New topic

Problem with loading driver

Popescu Ion
Ranch Hand

Joined: Jan 14, 2011
Posts: 33

i get this error :
Exception in thread "main" java.lang.NoClassDefFoundError: LoadDriver
Caused by: java.lang.ClassNotFoundException: LoadDriver
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
Could not find the main class: LoadDriver. Program will exit.

I already created a environment variable named CLASSPATH and give it value = C:\mysql-connector-java-5.1.14\mysql-connector-java-5.1.14-bin.jar.
What can be the problem. Please help. Thnx in advance.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Look carefully at the error message. It tells you exactly what class couldn't be found.

And what is that class? Its name is "LoadDriver". That's the class you wrote, isn't it?

Now look at the classpath you set. It consists of only one jar file. Is the class you wrote in that jar file? I think you will find it is not. Therefore, since LoadDriver isn't in that jar file, it isn't in the classpath. And therefore it can't be loaded. Obvious, right? (And nothing to do with JDBC.)
Popescu Ion
Ranch Hand

Joined: Jan 14, 2011
Posts: 33
I can't figure out what value should i put in CLASSPATH - the folder location of conncetor/j or the jar file? Should I put the class that i created in that folder too? I'am totaly wracked. Please don't leave me without an answer. I had been on this since yesterday and without results. Thnx in advance for your patience.
Jan Cumps

Joined: Dec 20, 2006
Posts: 2565

Should I put the class that i created in that folder too?
No. Add it's location to the classpath.

OCUP UML fundamental and ITIL foundation
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
I strongly recommend not to use the CLASSPATH environment variable; it creates more problems than it solves, particularly for beginners. You can run your code using the "-cp" command line option instead, something like:

java -cp .;C:\mysql-connector-java-5.1.14\mysql-connector-java-5.1.14-bin.jar LoadDriver

Note the "." at the beginning of the classpath - it denotes the current directory (which should have the LoadDriver class in it).
I agree. Here's the link:
subject: Problem with loading driver
It's not a secret anymore!