mysql java connection error

797 views Asked by At

I am running my JAR file in linux (centos). All jar files work fine.

Now i am trying to connect to mysql server, but it gave me following error.

Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

I don't have server root access. I have a simple user account. I downloaded mysql.jar file for db connection, and put that in lib folder. Jar file contains lib path in .CLASSPATH file.

EDIT

I am running Jar file at command line

java -jar prog.jar

3

There are 3 answers

6
CoolBeans On BEST ANSWER

Try this java -cp path\to\your\mysql.jar -jar prog.jar

0
vz0 On

To run the application from the command line you need to specify the CLASSPATH as a command line argument:

java -cp mysql.jar -jar prog.jar
0
Nick On

The .CLASSPATH file is an eclipse project file which will not be used when executing from the command line. Try following this guide to set your classpath.