我将值插入到数据库中,但得到“列计数与列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'的模式定义吗? –
您的登录表中可能包含更多字段。 –