我有这个小代码用于将我的 jsp 连接到我的 mysql 数据库。
String driver = "com.mysql.jdbc.Driver";
Class.forName(driver);
String url="jdbc:mysql://localhost:3306/test1";
Connection con = DriverManager.getConnection(url, "test1", "test1");
Statement cmd = con.createStatement();
String query = "SELECT * FROM champions";
ResultSet res = cmd.executeQuery(query);
while (res.next()) {
System.out.print(res.getString("name") + ", ");
System.out.println(res.getString("title"));
}
res.close(); // chiudere le risorse DB è obbligatorio
cmd.close();
con.close();
我已将连接器添加到我的构建路径中:
但我仍然收到此错误:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
有人可以帮助我吗?