我正在尝试编写一个连接到 MySQL 数据库的 java 程序。但我收到此错误:
找不到适合 jdbc:mysql//localhost:3306/test 的驱动程序
我已经安装了mysql-connector-java.5.1.23-bin.jar
. 我仍然收到此错误。
这是我的程序:
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;
}
}