Monday, 7 March 2016

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

Hello friends. As you know I am Oracle DBA but sometime we need to do work out of our scope to find the solution. Today morning my Manager asked gave me a JAVA file and asked me to run on Ubuntu operating system running in our environment. I installed Java using myblog. While running the java file I was getting following error:














To resolve this issue, I followed these steps:
  1. Go to MySQL link.


   2. Download the platform independent "mysql-connector-java-5.0.8.tar.gz"
   3. Create a directory "java" inside /home/<user_name>.
   4. Copy this file to Ubuntu server in the directory created in previous step.
   5. Unzip the file in same directory (# sudo tar -zxcf mysql-connector-java-5.0.8.tar.gz")
   6. Now set CLASSPATH variable in your environment.
  •    # export CLASSPATH=/home/<user_name>/java/mysql-connector-java-5.0.8/mysql-connector-java-5.0.8-bin.jar
  • Verify the CLASSPATH variable: echo $CLASSPATH, it should reflect the path set in previous step.
   7. Run the java file: #java -cp $CLASSPATH util.MySQLTest
    
Note: All class files should exist in the same directory to which CLASSPATH variable is pointing.

Please let me know if you face any issue in this.

No comments:

Post a Comment