I Have Created Registration Jsp and Servlet.When I Insert the Values Using Form,Values not inserted as well as Some Exception come on Apache Log.Can any one Help me to Find actual Error.in my query or Connection????
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 [...]
The offending method:
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);
}
}
In your insert statement, the number of columns you have supplied is not the same as the number of values you specified.
e.g.
insert into Table 1 (A, B, C) values (100, 1001, 1002, 1004).
=> 3 columns != 4 Values.