Error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Hello Friends,

You may have come across “java.lang.ClassNotFoundException: com.mysql.jdbc.Driver” error/exception while working with java and JDBC. The error occurs mainly when we try to connect to the mySql database from our java code. The error message itself give the clear indication about what we are missing. It says that it is unable to find the Class – “com.mysql.jdbc.Driver”.

Now, this exception is mainly due to unavailability of the mysql-connector jar file which contains the required class which is missing while the compilation of the code. This jar file contains many other classes those are listed in the below table

What you need to do is, just add the mysql-connector-java jar file in the build path of your program and then run the program again. Your program will run and execute properly. You can download the jar from MySql download link.

Hope this will help you.

Regards,

Nikhil Naoghare.

1 Comment

  1. Javin

    Thanks for fix. sometime you need correct version of JDBC driver as well. I have shared few tips here http://javarevisited.blogspot.com/2012/03/jdbc-javalangclassnotfoundexception.html Fixing java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Java

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *