jdbc - JdbcTemplate, MySQL error -
need help! have asked question here earlier - mysql/java error related 1 not identical (not sure of protocols @ such questions). working jdbc, mysql , encountering errors. first, code
public user find(string login) { system.out.println("trying find user...." + login); user user = this.jdbctemplate.queryforobject( "select * xyz user_name = ?", new object[]{login}, new rowmapper<user>() { public user maprow(resultset rs, int rownum) throws sqlexception { user user = new user(); user.setid(long.valueof(rs.getint(1))); user.setusername(rs.getstring(2)); user.setpassword(rs.getstring(3)); return user; } }); system.out.println("found user..." + user); return user; } public void create(user user) { this.jdbctemplate.update("insert xyz (user_name,user_password) values (default, default, ?, ?)", new object[] {user.getusername(),user.getpassword()});
i need give default values user_name, user_password (the 2 columns) don't know how , in "create(user user) block.
here's error code above:
severe: servlet.service() servlet appservlet threw exception java.sql.sqlexception: column count doesn't match value count @ row 1
i have tried without 'default', 'default' , (?, ?) gives me yet error.
severe: servlet.service() servlet appservlet threw exception com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: have error in sql syntax; check manual corresponds mysql server version right syntax use near '?,?)' @ line 1
your column list has 2 columns, , you're trying insert 4 values.
insert xyz (user_name,user_password) values (default, default, ?, ?)
drop default
values if column has default , not specified in column list.
Comments
Post a Comment