This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund 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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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
Bartender

Joined: Aug 16, 2005
Posts: 12918
    
    3

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 7 API documentation
Scala Notes - My blog about Scala
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: 16483
    
    2

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
Bartender

Joined: Aug 16, 2005
Posts: 12918
    
    3

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: ClassNotFoundException for MySQL
 
Similar Threads
Question No. 11- Chapter 10 K&B book SCJP 1.6 - Doubt on Answer
Exception in thread "main" java.lang.NoClassDefFoundError: Voice1
please help running programs created in jsdk 1.4 into jsdk 1.6
Starting Websphere 6.0 in Eclipse3.3
Jboss is not running.Exception in thread "main"