This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Mysql jdbc connector giving class def not found error  RSS feed

 
Shweta Grewal
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the entire exception stacktrace that you see when you place that jar in the classpath.
 
Campbell Ritchie
Sheriff
Posts: 53740
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, please show us the classpath you are using in that application.
 
Shweta Grewal
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!