使用Java时,我在try 连接mysql数据库时遇到以下错误:
java.sql.SQLException: No suitable driver found for
jdbc:mysql://localhost:3306/mysql at
java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at MyTest1.main(MyTest1.java:28)
我用的是mysql-connector-java-5.1.18-bin.jar
司机.它在我的构建路径中.我重新启动了MySQL.我也从命令行用root登录,没有密码,连接良好.我目前在netstat中没有看到3306端口.之前我遇到了一个不同的错误(我没有更改代码).错误为"拒绝用户'root'@'localhost密码号的jdbc mysql访问"
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
String url = "jdbc:mysql://localhost:3306/mysql";
Connection con = DriverManager.getConnection(url, "root", "");
}
catch (Exception e){
e.printStackTrace();
}