0
需要帮助!我之前在这里提出过一个问题 - MySQL/Java error与此相关但不完全相同(对于这些问题,不确定SO的协议)。我正在使用JDBC,MySQL并遇到错误。首先,代码JdbcTemplate,MySQL错误
public User find(String login) {
System.out.println("Trying to find the user...." + login);
User user = this.jdbcTemplate.queryForObject(
"select * from xyz where 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 INTO xyz (user_name,user_password) VALUES (default, default, ?, ?)",
new Object[] {user.getUserName(),user.getPassword()});
我需要给默认值USER_NAME,USER_PASSWORD(2列),但不知道在“创建(用户用户)块的方式和地点。
下面是上面的代码中的错误:(?)。
SEVERE: Servlet.service() for servlet appServlet threw exception
java.sql.SQLException: Column count doesn't match value count at row 1
我已经尝试过了没有“默认”,“默认”,只是但这给了我又一个错误
SEVERE: Servlet.service() for servlet appServlet threw exception
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server version for the
right syntax to use near '?,?)' at line 1
Thx :)我刚刚编辑了这个问题,以表明错误,当我尝试没有'默认',只是(?,?)。 – user2480526
MySQL表格没有这些列的默认值。 – user2480526
@ user2480526你已经改变了你的问题。你的列名真的是'user_name'和'user_password'吗?如果您使用[保留字](http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html) – Kermit