This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes ClassNotFoundException for MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ClassNotFoundException for MySQL" Watch "ClassNotFoundException for MySQL" New topic
Author

ClassNotFoundException for MySQL

Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

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....


Never try to be a hard-worker. Be a smart-worker.
My Blog
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14193
    
  20

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 ...


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

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

Joined: Oct 11, 2007
Posts: 60
Java isn't going to see the mysql jar unless it is on the classpath which is what it is complaining about.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Aug 16, 2005
Posts: 14193
    
  20

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

Joined: May 29, 2008
Posts: 445

Thanks for your help, Ranchers. Thanks for clearing me....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassNotFoundException for MySQL