简体   繁体   中英

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

I work with IntellJ So I have this code ( Username and Password changed ):

    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

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??

Your connection string looks okay. I'm assuming you're using maven to build. If so, do you have the following in your.pom file or included in your project? 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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