Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mysql jdbc connector giving class def not found error

 
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
Marshal
Pie
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: 48921
58
  • 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: 21107
32
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic