[英]No suitable driver found for jdbc:mysql//localhost:3306/test
I am trying to write a java program connecting to a MySQL database. 我正在尝试编写一个连接MySQL数据库的Java程序。 But I am getting this error:
但我收到此错误:
No suitable driver found for jdbc:mysql//localhost:3306/test
找不到适用于jdbc:mysql // localhost:3306 / test的驱动程序
I have already installed mysql-connector-java.5.1.23-bin.jar
. 我已经安装了
mysql-connector-java.5.1.23-bin.jar
。 I am still getting this error. 我仍然收到此错误。
Here is my program: 这是我的程序:
package database_practice;
import java.sql.*;
public class CreateConnection {
private Connection conn = null;
public static void main(String args[]) {
CreateConnection conn = new CreateConnection();
conn.getConnection();
}
public Connection getConnection() {
try {
String url = "jdbc:mysql//localhost:3306/test";
String username = "root";
String password = "admin1234";
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, username, password);
System.out.println("Database Created...!!!");
}
catch (Exception e) {
e.printStackTrace();
System.out.println("Error occured while connecting to database");
}
return conn;
}
}
Your connection string is wrong. 您的连接字符串错误。 This:
这个:
"jdbc:mysql//localhost:3306/test"
should be: 应该:
"jdbc:mysql://localhost:3306/test"
Note the colon after " mysql
". 注意“
mysql
”后的冒号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.