This discussion is archived
1 Reply Latest reply: Sep 25, 2012 4:00 AM by gimbal2 RSS

JDBC Connect problem on Linux: com.mysql.jdbc.Driver

928518 Newbie
Currently Being Moderated
Hi All,
I have a simple java application which reads data from the DB. The application works fine on windows. I have added the 'mysql-connector-java-5.1.22-bin.jar' in my windows classpath.
The problem comes when i copy the application on linux and run it. I getthe following exception:
root@HH-Linux1:/opt/integra/middleware/LCPAnalyzer/src# javac LCPAnalyzer.java
root@HH-Linux1:/opt/integra/middleware/LCPAnalyzer/src# java LCPAnalyzer
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:186)
        at LCPAnalyzer.connectDB(LCPAnalyzer.java:47)
        at LCPAnalyzer.main(LCPAnalyzer.java:32)
I have read various articles on setting classpath in linux, but couldn't get through and I am still unclear as to how to set the classpath in linux?

I even copied the 'mysql-connector-java-5.1.22-bin.jar' in my project src folder where the .class file is generated but still no success.

I also tried setting the classpath at runtime by: export CLASSPATH=/opt/integra/middleware/LCPAnalyzer/src/mysql-connector-java-5.1.22-bin.jar

but then i got the follwoing exception:
root@HH-Linux1:/opt/integra/middleware/LCPAnalyzer/src# javac LCPAnalyzer.java
root@HH-Linux1:/opt/integra/middleware/LCPAnalyzer/src# java LCPAnalyzer
Exception in thread "main" java.lang.NoClassDefFoundError: LCPAnalyzer
Caused by: java.lang.ClassNotFoundException: LCPAnalyzer
I am totally lost as how to proceed now. Could someone please suggest a permanent way to set classpath in linux. I have few other java mail api related jars as well, which i would want to set in the classpath in linux but first want to resolve this mysql connector problem.

Any help woudl really be appreciated.

Thanks
  • 1. Re: JDBC Connect problem on Linux: com.mysql.jdbc.Driver
    gimbal2 Guru
    Currently Being Moderated
    925515 wrote:
    I have read various articles on setting classpath in linux, but couldn't get through and I am still unclear as to how to set the classpath in linux?
    The same way as in Windows, only in stead of a semilcolon ( ; ) as a separator you use a colon ( : ). The rest is as simple as figuring out how to set environmental variables in your particular flavor of Linux; if you want help with that I suggest a Linux forum that is dedicated to your distribution.

    Of course you are always free to set the classpath by passing it to the java command using the -cp command line switch, or create an executable jar which takes away all need to set any kind of classpath (in stead it is configured in the jar itself).

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points