我在连接我的 java 和 mysql 数据库时遇到问题,昨天工作正常,但现在不工作,这是我的代码。
public static void main(String[] args) {
try
{
Class.forName ("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e)
{
System.out.println ("Could not load the driver");
}
String user, pass, host, database;
user = "Michael";
pass = "Blaine22";
host = "localhost";
database = "maintenance_work";
Connection conn = DriverManager.getConnection
("jdbc:mysql://"+host+":3306/"+database, user, pass);
conn.setAutoCommit(false);
//Menu code:
appSchoolMaintenance newWork = new appSchoolMaintenance();
newWork.statement1(); // opens the start method
}
最佳答案
将 MySQL JDBC 驱动程序(您可以在此处获取:http://dev.mysql.com/downloads/connector/j/)添加到应用程序的类路径并删除不必要的代码段:
try
{
Class.forName ("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e)
{
System.out.println ("Could not load the driver");
}
关于java - 无法加载驱动程序 java.sql.SQLException : No suitable driver found for jdbc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23148859/