连接到mysql本地主机数据库

时间:2019-04-09 23:29:10

标签: java

我是Java网络方面的新手。由于某种原因,我的java文件无法连接到localhost数据库。我不断收到错误消息。请帮助

test.java:

import java.sql.*;

class test {
    public static void main(String[] args) {
        try {
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/user", "root", "");
        } catch(Exception exp) {
            exp.printStackTrace();
        }
    }
}

error:

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/user
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at test.main(test.java:7)

directory:

enter image description here

1 个答案:

答案 0 :(得分:-1)

我认为您应该添加jar连接器(https://dev.mysql.com/downloads/connector/j/