[英]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.