Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassNotFoundException for MySQL

 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I write a simple POI Java File to read the values from Excel and store them in MySQL.The program compiled and when i try to run the program, it shows an error like this:

C:\java\jdk1.6\bin>java -classpath c:\java\jdk1.6\lib\poi-3.5-beta1-20080718.jar
;c:\java\jdk1.6\bin ReadExcel
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at ReadExcel.main(ReadExcel.java:52)


I understand the error, but i already have the jdbc driver in the jdk\lib folder.... So, i am sure that problem is at somewhere else...
Please let me know what's wrong i did with the program....

Help me ranchers....
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15436
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, it's not a good idea to put JAR files in the JDK lib directory. Also, the JDK bin directory does not need to be in your classpath at all - unless you put your own class files in the JDK bin directory, which is also not a good idea...

Just put all the JAR files that your application needs in the classpath:

C:\java\jdk1.6\bin>java -classpath c:\java\jdk1.6\lib\poi-3.5-beta1-20080718.jar;C:\...\mysqldriver.jar ...
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jesper Young:
In general, it's not a good idea to put JAR files in the JDK lib directory. Also, the JDK bin directory does not need to be in your classpath at all - unless you put your own class files in the JDK bin directory, which is also not a good idea...

Just put all the JAR files that your application needs in the classpath:

C:\java\jdk1.6\bin>java -classpath c:\java\jdk1.6\lib\poi-3.5-beta1-20080718.jar;C:\...\mysqldriver.jar ...


But i dont have any application... I use this file to extract bulk amount of entries from excel and insert them into excel...So jdk bin is enough for me... If this is the case, what is the solution?
 
Iain Emsley
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java isn't going to see the mysql jar unless it is on the classpath which is what it is complaining about.
 
Paul Clapham
Sheriff
Posts: 21314
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rajkumar balakrishnan:
But i dont have any application...
Then what is that "ReadExcel" thing in your command line?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15436
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rajkumar balakrishnan:
But i dont have any application... I use this file to extract bulk amount of entries from excel and insert them into excel...So jdk bin is enough for me... If this is the case, what is the solution?

Just create a directory somewhere on your harddisk, for example C:\Projects\ReadExcel. Put your ReadExcel.java source file there and compile it:

C:\Projects\ReadExcel> javac ReadExcel.java

Also put the necessary JAR files in the same directory, and then run it with the correct classpath:

C:\Projects\ReadExcel> java -classpath poi-3.5-beta1-20080718.jar;mysqldriver.jar;. ReadExcel

(Note, I don't know in what JAR file the MySQL driver is; you'll need to put the right filename in the classpath.

You should never put your own files in the JDK directories.
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help, Ranchers. Thanks for clearing me....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic