我有以下代码连接到 mysql 数据库:
public static void insertIntoDatabase(String code,String name,String temp,String hum,String del) {
Connection con = null;
ResultSet rs = null;
String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
String password = "";
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, user, password);
rs = con.prepareStatement("CREATE TABLE IF NOT EXISTS AiportDetails(code VARCHAR(50) PRIMARY KEY, " +
"name VARCHAR(50), temp VARCHAR(50), hum VARCHAR(50), del VARCHAR(50)) ENGINE=InnoDB;").executeQuery();
rs = con.prepareStatement("INSERT INTO AirportDetails(code,name,temp,hum,del) VALUES("+code+","+
name+","+temp+","+hum+","+del+");").executeQuery();
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
我收到以下错误:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
注意我在网上找到的一些常见更正是:
1. The driver is not in the /WEB-INF/lib folder.
2. The url is wrong.
我不认为这是我的代码的情况。
谢谢你。