Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
728 views
in Technique[技术] by (71.8m points)

web applications - JDBC Driver class not found: com.mysql.jdbc.Driver

I am developing a web application using maven spring and hibernate and I need to create schema using hibernate for which I had the following in my pom.xml to connect to MySQL 5.5 database.

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

This imported mysql-connector-java-5.1.15.jar in my Libraries under Maven Dependencies but when I try to connect to database it gives me Exception in thread "main" org.hibernate.HibernateException: JDBC Driver class not found: com.mysql.jdbc.Driver.

I have done this like gazillions of times, but I did it when I din't used to use Maven to manage my dependencies and build the project. I just used to have it the same jar file in the lib folder of a Dynamic Web Project in Eclipse IDE.

Could someone tell me what am I missing here and what else I need to have this jar in my build path?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:Librariesmysql-connector-java-5.1.15-binmysql-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> 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...