Friday, April 15, 2011

Published 4/15/2011 by with 2 comments

ClassNotFoundException: com.mysql.jdbc.Driver

This error occurs when the required JDBC driver file is not in the CLASSPATH. Also, if the driver name is not correct ClassNotFoundException occurs. To solve this problem, at first check the driver name; if the driver name is correct, do one of the followings as per requirement.

i) Add an entry for the driver file (mysql-connector-java-5.1.10.jar, for example) in the CLASSPATH variable.

or

ii) If you are not familiar with the CLASSPATH variable, place the mysql-connector-java-5.1.10.jar file in \jre\lib\ext folder in the JDK install directory (for example C:\Program Files\Java\jdk1.6.0_20\jre\lib\ext)

or

iii) If you are doing this in NetBeans or other IDEs, add MySQL JDBC Driver Library in the project.
    email this       edit

2 comments:

  1. Nice article , you have indeed covered topic in details with sample code, its indeed a topic which require a deeper understanding than many other java topics.

    Thanks
    Javin
    How Classpath works in Java

    ReplyDelete
  2. thank you for help this bug gives me headache..

    ReplyDelete