JDBC Driver class not found: com.mysql.jdbc.Driver

Unzip your generated JAR file. There is a folder WEB-INF in. Then check if mysql-connector-java-5.1.15.jar exists in this WEB-INF/lib.


To start with, the jar that I need to connect to MySQL 5.5 should have been mysql-connector-java-5.1.15-bin.jar but not mysql-connector-java-5.1.15.jar. Secondly, this jar is not available in maven repository so I needed to manually add it to my local maven repository and then added it as a dependency in my pom.xml.

Adding mysql-connector-java-5.1.15-bin.jar to the local maven repository by

mvn install:install-file -Dfile=C:\Libraries\mysql-connector-java-5.1.15-bin\mysql-connector-java-5.1.15-bin.jar -DgroupId=mysql -DartifactId=mysql-connector-java -Dversion=5.1.15-bin -Dpackaging=jar

and then adding the following dependency to pom.xml of the project.

    <!-- MySql 5.5 Connector -->   
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.15-bin</version>
    </dependency> 

Thanks for the answers above - just a comment for NetBeans users: (names to be replaced with your versions)

  1. The mysql JAR can be downloaded here
  2. mvn executable can be found at c:\Program Files\NetBeans 7.2.1\java\maven\bin
  3. run set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_10
  4. Then the above command would work: mvn install:install-file -Dfile=mysql-connector-java-5.1.15-bin.jar -DgroupId=mysql -DartifactId=mysql-connector-java -Dversion=5.1.15-bin -Dpackaging=jar
  5. installed package could be found in m2 repository in your home folder

My working solution

 <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.18</version>
</dependency>

adding above dependency to pom.xml works for me...