简体   繁体   English

在带有 MySQL 的 IntellJ 中找不到适合 jdbc:mysql 的驱动程序

[英]No suitable driver found for jdbc:mysql in IntellJ with MySQL

I work with IntellJ So I have this code ( Username and Password changed ):我使用 IntellJ 所以我有这个代码(用户名和密码已更改):

    String jdbcUrl = "jdbc:mysql://sql11.freesqldatabase.com:3306/sql11418144";
    String username = "user1234";
    String password = "abc";

    Connection con = DriverManager.getConnection(jdbcUrl, username, password);
    Statement stmt = con.createStatement();
    String url = "select name from table";
    ResultSet result = stmt.executeQuery(url);

    while (result.next()) {
        System.out.println(result.getString("name"));
    }

I use MySQL and I have these configurations: enter image description here我使用 MySQL 并且我有这些配置:在此处输入图像描述

But I have this Error:但我有这个错误:

java.sql.SQLException: No suitable driver found for jdbc:mysql://........

What can I do?我能做些什么? I can run SELECT COMMANDS in IntellJ but not with JAVA??我可以在 IntellJ 中运行 SELECT COMMANDS 但不能在 JAVA 中运行?

Your connection string looks okay.您的连接字符串看起来不错。 I'm assuming you're using maven to build.我假设您正在使用 maven 进行构建。 If so, do you have the following in your.pom file or included in your project?如果是这样,您的 .pom 文件中是否包含以下内容或包含在您的项目中? https://mvnrepository.com/artifact/mysql/mysql-connector-java https://mvnrepository.com/artifact/mysql/mysql-connector-java

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM