wood burning stoves 2.0*
The moose likes JDBC and the fly likes Mysql jdbc connector giving class def not found error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Mysql jdbc connector giving class def not found error" Watch "Mysql jdbc connector giving class def not found error" New topic
Author

Mysql jdbc connector giving class def not found error

Shweta Grewal
Ranch Hand

Joined: Apr 03, 2012
Posts: 39
I wrote a program to retrieve data from a table in mysql. Now if I provide /mysql-connector-java-5.0.8-bin.jar in classpath.The error is
Exception in thread "main" java.lang.NoClassDefFoundError

But if I dont provide connector in classpath, the program runs but prints
mysql driver not found

I am on linux
Please help
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10146
    
165

Please post the entire exception stacktrace that you see when you place that jar in the classpath.

[My Blog] [JavaRanch Journal]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
Also, please show us the classpath you are using in that application.
Shweta Grewal
Ranch Hand

Joined: Apr 03, 2012
Posts: 39
Stack trace is:
Exception in thread "main" java.lang.NoClassDefFoundError: SelectApp
Caused by: java.lang.ClassNotFoundException: SelectApp
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: SelectApp. Program will exit.

please show us the classpath you are using in that application

mysql-connector-java-3.1.12.jar(It is in same directory as program)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Okay... and is your SelectApp class in that jar?

Let's save some time, we both know that it isn't. And since the jar is now the only thing in your classpath, SelectApp isn't in the classpath. And therefore the JVM can't load it, and therefore you get that message.

So fix your classpath so that it contains the folder where SelectApp is located and also the JDBC Connector jar file.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Mysql jdbc connector giving class def not found error