【发布时间】:2015-06-27 09:02:14
【问题描述】:
我有一种方法可以检测列的重复条目:
(我正确地注入到jdbcTemplate)
private boolean isDuplicate(String username) {
String sql = " select username from users where username=?";
int result = jdbcTemplate.update(sql, new Object[]{username}, String.class);
return result;
}
但我在运行时遇到了这个异常:
org.springframework.dao.TransientDataAccessResourceException:
PreparedStatementCallback; SQL [ select username from users where username=?]; Invalid argument value: java.lang.ArrayIndexOutOfBoundsException;
nested exception is java.sql.SQLException: Invalid argument value: java.lang.ArrayIndexOutOfBoundsException
【问题讨论】:
-
一开始你不是通过模板
update,而是queryForObject。其次,您返回一个用户名,即String。不是整数或布尔值。