繁体   English   中英

发现此错误“没有找到适合 jdbc:mysql//localhost:3306/student 的驱动程序”

[英]Found this error "No suitable driver found for jdbc:mysql//localhost:3306/student"

我试图在IntelliJ IDEA中创建简单的 java 学生GUI应用程序,并且工作正常。 然后我只是尝试连接数据库以将所有数据插入 MYSQL,所以我在MySQL Workbatch中创建模式( student )和表( appointment ),然后在IntelliJ IDEA Database Z05B8C74CBD96FBF2DE4C1A3527 中连接该数据库,您可以在图片中看到它成功配置的 FBF2DE4C1A3527 .

现在我尝试通过下面的行创建连接。

Connection con = DriverManager.getConnection("jdbc:mysql//localhost:3306/student","root","root");

但是这一行给了我这个错误Error: No suitable driver found for jdbc:mysql//localhost:3306/student

所以我谷歌它,我找到了这条线。

Class.forName("com.mysql.cj.jdbc.Driver");

但是这条线给出了这个错误Error: com.mysql.cj.jdbc.Driver

请大家看看它,它对我和其他面临这个问题的人非常有帮助。

在此处输入图像描述

 private DBconnectionSingleton() throws SQLException {
    // create single instance of DB connection 
    Properties connectionProps = new Properties();
    connectionProps.put("user", login);
    connectionProps.put("password", password);// port & db name
    System.out.println("Loading driver...");


    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
        System.out.println("Driver loaded!");
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException("Cannot find the driver in the classpath!", e);
    }

    conn = DriverManager.getConnection(
            "jdbc:mysql://localhost:3306/student",
            connectionProps
    );
}

暂无
暂无

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

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