使用com.mysql.cj.jdbc.Driver,MySQL Connector和IntelliJ IDEA的ClassNotFoundException [英] ClassNotFoundException with com.mysql.cj.jdbc.Driver, MySQL Connector and IntelliJ IDEA

查看:5299
本文介绍了使用com.mysql.cj.jdbc.Driver,MySQL Connector和IntelliJ IDEA的ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Maven Java 1.8项目,其中我将MySQL Connector作为依赖项包含在内:

I'm building up a Maven Java 1.8 project in which I've included the MySQL Connector as a dependency:

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

在我的应用程序中,我有一个包含MySQL连接的单例,所以当应用程序启动时,MySQL连接器被触发但我得到的驱动程序 ClassNotFoundException com.mysql.cj.jdbc.Driver

In my application I've a singleton that holds the MySQL connection so when the application starts, the MySQL connector is triggered but I got a ClassNotFoundException for the driver that I'm using: com.mysql.cj.jdbc.Driver.

我正在使用的JDBC URL是:

The JDBC URL that I'm using is:

jdbc:mysql:// localhost:3306 / mydb?autoReconnect = true& useSSL = false

我正在使用IntelliJ IDEA(2017.2)IDE。

I'm using IntelliJ IDEA (2017.2) IDE.

我'检查文件 - >项目结构 - >库 - >我看到Maven:mysql:mysql-connector-java:5.1.392作为库。

I've checked in File -> Project Structure -> Libraries -> I see "Maven: mysql:mysql-connector-java:5.1.392" as a Library.

I还检查了文件 - >项目结构 - >工件 - >并在myapp.war爆炸 - > WEB-INF - > lib - > Maven:mysql:mysql-connector-java:5.1.39存在。

I've also checked under File -> Project Structure -> Artifacts -> and under myapp.war exploded -> WEB-INF -> lib -> Maven: mysql:mysql-connector-java:5.1.39 is present.

从视图 - >工具窗口 - >数据库,我成功地建立了一个MySQL连接,下载了建议的驱动程序(MySQL Connector 5.1.35)。

From View -> Tool Windows -> Database, I've succesfully made a MySQL connection dowloading the suggested driver (MySQL Connector 5.1.35).

如何判断应用程序是否必须在运行时加载MySQL驱动程序?

How can I tell the application that it has to load the MySQL driver at runtime?

提前致谢

推荐答案

看起来您正在尝试将JDBC DriverManager用于版本8 查看此。尝试使用 com.mysql.jdbc.Driver 驱动程序而不是 com.mysql.cj.jdbc.Driver

It looks like you are trying to use the JDBC DriverManager for version 8 check out this. Try to use com.mysql.jdbc.Driver driver instead of com.mysql.cj.jdbc.Driver.

这篇关于使用com.mysql.cj.jdbc.Driver,MySQL Connector和IntelliJ IDEA的ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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