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

查看:130
本文介绍了找不到 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 但是当我尝试连接到数据库它给了我 线程main" org.hibernate.HibernateException 中的异常:找不到 JDBC 驱动程序类: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.

通过

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

然后在项目的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天全站免登陆