可能重复:
java.sql.SQLException: No suitable driver found for localhost test
我正在尝试使用Java语言建立第一个与数据库的连接。这是我到目前为止的代码:
import java.sql.*;
public class Database {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql:mud", "myusername", "mypassword");
Statement stmt = con.createStatement();
}
}
我还在JRE / lib / ex中添加了MySQL连接器.jar。我尝试用“java Database”运行程序。我收到这个错误:
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:mysql:mud
at java.sql.DriverManager.getConnection(DriverManager.java:640)
at java.sql.DriverManager.getConnection(DriverManager.java:200)
at Database.main(Database.java:8)
我将不胜感激任何帮助。感谢。