try
{
String userName = "root";
String password = "";
//<facility> is my database
String url = "jdbc:mysql://localhost/facility";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
System.out.println ("Cannot connect to database server " +e.getClass().getName());
}
输出> 无法连接到数据库服务器 java.lang.ClassNotFoundException
最佳答案
看来您应该将 MySQL 驱动程序 jar 放入您的类路径中。
关于java - 找不到 JDBC 驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5390604/