• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ClassNotFoundException for MySQL

 
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help, Ranchers. Thanks for clearing me....
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic