我將值插入到數據庫中,但得到「列計數與列1中的值計數值不匹配」錯誤。「列計數與第1行的值計數不匹配」程序中的錯誤
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionURL, "root", "root");
String sql = "insert into login(username,password) values(?,?)";
PreparedStatement pst = connection.prepareStatement(sql);
pst.setString(1, username);
pst.setString(2, password);
int numRowsChanged = pst.executeUpdate();
out.println(" Data has been submitted ");
pst.close();
} catch (ClassNotFoundException e) {
out.println("Couldn't load database driver: " + e.getMessage());
} catch (SQLException e) {
out.println("SQLException caught: " + e.getMessage());
} catch (Exception e) {
out.println(e);
} finally {
try {
if (connection != null)
connection.close();
} catch (SQLException ignored) {
out.println(ignored);
}
}
這是我的表MySql數據庫:
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| username | varchar(20) | YES | | NULL | |
| password | varchar(15) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
爲什麼會出現這個錯誤?我的代碼有問題嗎? 請幫助我.......
你有多少字段進入登錄表? – Pratik
你能告訴我們表'login'的模式定義嗎? –
您的登錄表中可能包含更多字段。 –