我已经创建了注册 Jsp 和 Servlet。当我使用表单插入值时,未插入的值以及 Apache 日志上出现一些异常。谁能帮我找到实际的错误。在我的查询或连接中????
Jul 27, 2012 9:00:30 PM com.asiahospital.db.DataPersistor registerUser
SEVERE: null
java.sql.SQLException: Column count doesn't match value count at row 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2618)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:842)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:681)
at com.example.db.DataPersistor.registerUser(DataPersistor.java:29)
at com.example.servlet.RegistrationServlet.doPost(RegistrationServlet.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at [...]
违规方法:
public void registerUser(User user) {
try {
Statement stmt = con.createStatement();
String query = "INSERT INTO user VALUES ('" + user.getUserName()+ "','"
+ user.getPassword() + "','" + user.getFirstName() + "','"
+ user.getLastName() + "','" + user.getEmail() + "','false')";
stmt.execute(query);
} catch (SQLException ex) {
Logger.getLogger(DataPersistor.class.getName()).log(Level.SEVERE, null, ex);
}
}