Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql jdbcTemplate更新中的Spring瞬态数据访问资源异常_Sql_Spring_Jdbc - Fatal编程技术网

Sql jdbcTemplate更新中的Spring瞬态数据访问资源异常

Sql jdbcTemplate更新中的Spring瞬态数据访问资源异常,sql,spring,jdbc,Sql,Spring,Jdbc,我有一种方法可以检测列的重复条目: (我正确地注入到jdbcTemplate) 但我在运行时遇到了这个异常: org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [ select username from users where username=?]; Invalid argument value: java.lang.ArrayIndexOutOfBou

我有一种方法可以检测列的重复条目:

(我正确地注入到
jdbcTemplate

但我在运行时遇到了这个异常:

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

我们可以像这样使用
jdbcTemplate
queryForList()
方法:

results = jdbcTemplate.queryForList(sql,new Object[]{username},String.class);

if(results.isEmpty(){
  //no duplicate
}

else{
  //duplicate
}

其中,
results
是一个
列表

对于start,您不通过模板
更新
,而是
查询对象
。其次,您返回一个用户名,因此
String
。不是int或boolean。
results = jdbcTemplate.queryForList(sql,new Object[]{username},String.class);

if(results.isEmpty(){
  //no duplicate
}

else{
  //duplicate
}