我已将JDBC连接器添加到我的类路径中,但我仍然收到" java.lang.ClassNotFoundException:com.mysql.jdbc.Driver"错误信息。我的代码是否有错,我没看到?
import java.sql.Connection;
import java.sql.DriverManager;
public class DBConnect {
public static Connection conn = null;
public static Connection ConnectDB () {
try {
Class.forName("com.mysql.jdbc.Driver");
conn =
DriverManager.getConnection("jdbc:mysql://localhost/destore",
"root", "1234");
return conn;
}catch(Exception e) {
javax.swing.JOptionPane.showMessageDialog(null, e);
return null;
}
}
}
答案 0 :(得分:0)
添加端口号
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/"+dbname,username,pwd);