Right now I have a class "ShowDataBase" which create a connection to mySQL database. So I put mysql-connector-java-3.1.10-bin.jar and ShowDataBase.class together in one directory. When I run java ShowDataBase,it shows following:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at ShowDataBase.main(ShowDataBase.java:30)
however, if I run "java -cp mysql-connector-java-3.1.10-bin.jar ShowDataBase", it displays:
Exception in thread "main" java.lang.NoClassDefFoundError: ShowDataBase
I am sure the ShowDataBase run correctly until Ecipse and contains no error. Please help me out for this problem. I don't want to run it under Eclipse very time because it takes a lot memories.... Thx a lot.
I would have thought an SCJP would have classpath basics down. That would only work if ShowDataBase was in the default package and in the current directory. The -cp sets the CLASSPATH and the environment variable is NOT used. If you don't understand how to setup your classpath then I suggest getting an introductory book or looking at a tutorial. Here's something Google quickly turned up but I don't know how good it is: