Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Problem with loading driver

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


i get this error :

Exception in thread "main" java.lang.NoClassDefFoundError: LoadDriver
Caused by: java.lang.ClassNotFoundException: LoadDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
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.
 
Marshal
Posts: 27288
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Should I put the class that i created in that folder too?

No. Add it's location to the classpath.
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
reply
    Bookmark Topic Watch Topic
  • New Topic