找不到JDBC驱动程序类:com.mysql.jdbc.Driver [英] JDBC Driver class not found: com.mysql.jdbc.Driver

查看:3058
本文介绍了找不到JDBC驱动程序类:com.mysql.jdbc.Driver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用maven spring和hibernate开发一个Web应用程序,并且需要使用hibernate创建架构,为此我在pom.xml中具有以下内容以连接到MySQL 5.5数据库.

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>

这在Maven Dependencies下的Libraries中导入了mysql-connector-java-5.1.15.jar,但是当我尝试连接数据库时,它给了我Exception in thread "main" org.hibernate.HibernateException: JDBC Driver class not found: com.mysql.jdbc.Driver.

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.

我已经做过无数次这样的工作,但是当我不习惯使用Maven来管理我的依赖项和构建项目时,我做到了.我以前在Eclipse IDE中,在Dynamic Web Projectlib文件夹中拥有相同的jar文件.

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.

有人可以告诉我我在这里缺少什么,在构建路径中还需要这个jar吗?

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

谢谢.

推荐答案

首先,我需要连接到MySQL 5.5的jar应该是mysql-connector-java-5.1.15-bin.jar,而不是mysql-connector-java-5.1.15.jar.其次,此jar在maven存储库中不可用,因此我需要手动将其添加到本地maven存储库,然后将其作为依赖项添加到我的pom.xml中.

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.

通过以下方式将mysql-connector-java-5.1.15-bin.jar添加到本地Maven存储库中

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

,然后将以下依赖项添加到项目的pom.xml.

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> 

这篇关于找不到JDBC驱动程序类:com.mysql.jdbc.Driver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆