简体   繁体   English

找不到适用于jdbc:mysql // localhost:3306 / demo的驱动程序吗?useSSL = false

[英]No suitable driver found for jdbc:mysql//localhost:3306/demo?useSSL=false

I'm learning MySQL and I get this problem: 我正在学习MySQL,但遇到此问题:

No suitable driver found for jdbc:mysql//localhost:3306/demo?useSSL=false I have read other solutions but it's not working. 找不到适用于jdbc:mysql // localhost:3306 / demo?useSSL = false的驱动程序我已经阅读了其他解决方案,但是它不起作用。 This is my code: 这是我的代码:

package jdbc.test;
import java.sql.*;

public class JdbcInsertDemo {
    public static void main(String[] args) throws SQLException {

        Connection myConn = null;
        Statement myStmt = null;
        ResultSet myRs = null;

        String dbUrl = "jdbc:mysql//localhost:3306/demo?useSSL=false";
                //      jdbc:mysql//localhost:3306/demo?useSSL=false    
        String user = "student";
        String pass = "student";

        try {
            myConn = DriverManager.getConnection("jdbc:mysql//localhost:3306/demo?useSSL=false", user, pass);
            myStmt = myConn.createStatement();
            System.out.println("Inserting a new employee to database\n");

            int rowsAffected = myStmt.executeUpdate("Insert into employees" + "(last_name, first_name, email, department, salary)" + "values" + "('Wright' , 'Eric', 'eric.wright@foo.com', 'HR', 33000.00)");
            myRs = myStmt.executeQuery("slect * from employees order by last_name");

            while(myRs.next()) {
                System.out.println(myRs.getString("last_name") + ", " + myRs.getString("first_name"));
            }
        }

        catch(Exception exc) {
            exc.printStackTrace();
        }

        finally {
            if (myRs != null) {
                myRs.close();
            }
        }
    }
}

I think you forgot to include jar file in lib folder. 我认为您忘记在jar文件夹中包含jar文件。 Put the drive jar file in that folder and try again. 将驱动器jar文件放在该文件夹中,然后重试。

Theres a few things that could be wrong. 有些事情可能是错误的。

1 : Do you have the JDBC Jar included in the project references? 1:项目参考中是否包含JDBC Jar?

    myConn = DriverManager.getConnection("jdbc:mysql//localhost:3306/demo?useSSL=false", user, pass);

Also, for shorthand, since you have 'DbUrl' - MyConn can be simplified. 另外,简而言之,由于您具有“ DbUrl”,因此可以简化MyConn。

    String dbUrl = "jdbc:mysql//localhost:3306/demo?useSSL=false";
    myConn = DriverManager.getConnection(dbUrl, user, pass);

You have missed the Class.forName("com.mysql.jdbc.Driver"); 您已经错过了Class.forName("com.mysql.jdbc.Driver"); This line needs to be added before you get the connection object. 在获得连接对象之前,需要添加此行。

暂无
暂无

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

相关问题 JDBC JAVA找不到适合的驱动程序jdbc:mysql:// localhost:3306 / voting - JDBC JAVA No suitable driver found for jdbc:mysql://localhost:3306/voting 发现此错误“没有找到适合 jdbc:mysql//localhost:3306/student 的驱动程序” - Found this error "No suitable driver found for jdbc:mysql//localhost:3306/student" 如何解决:找不到适合jdbc的驱动:mysql://localhost:3306/sampledb - How to solve: No suitable driver found for jdbc:mysql://localhost:3306/sampledb 错误:找不到适用于jdbc:mysql:// localhost:3306 / test的驱动程序 - ERROR: No suitable driver found for jdbc:mysql://localhost:3306/test 找不到适用于jdbc:mysql:// localhost:3306 / jpa的驱动程序 - No suitable driver found for jdbc:mysql://localhost:3306/ jpa 找不到适用于jdbc:mysql // localhost:3306 / test的驱动程序 - No suitable driver found for jdbc:mysql//localhost:3306/test 找不到适用于jdbc:mysql:// localhost:3306 / test的驱动程序 - No suitable driver found for jdbc:mysql://localhost:3306/test 找不到适用于jdbc:mysql / localhost:3306 / world的驱动程序 - No suitable driver found for jdbc:mysql/localhost:3306/world Eclipse - Hibernate:没有为jdbc找到合适的驱动程序:mysql:// localhost:3306 / hibernatedb - Eclipse - Hibernate : No suitable driver found for jdbc:mysql://localhost:3306/hibernatedb SQLException:找不到适用于jdbc:mysql:// localhost:3306 / dbname的驱动程序 - SQLException: No suitable driver found for jdbc:mysql://localhost:3306/dbname
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM