gpt4 book ai didi

mysql - 使用 queryForObject() 方法检索计数时,JDBCTemplate 中的参数索引超出范围(1 > 参数数量,即 0)

转载 作者:行者123 更新时间:2023-11-29 16:48:19 37 4
gpt4 key购买 nike

我正在尝试使用 jdbctemplate.queryForObject(query,Object[]{},Integer.class) 方法获取行数,我在 mysql.properties 文件中定义了查询并将参数传递给 object[] 但仍然得到异常,请帮忙

 mysql.properties :
    getCustomerRows=SELECT count(cm.`customer_master_id`) FROM customer_master cm WHERE cm.branch_code =?;
  CustMasterDaoImpl :
    private @Value("${getCustomerRows") String getCustomerRows;
@Override
public Integer getCustomerRows(Integer branchCode) {
try {


return getJdbcTemplate().queryForObject(getCustomerRows,new Object[] {branchCode},Integer.class) ;
}catch (Exception e) {
logger.error("select Query failed : " + e.getMessage());
System.out.println("catch ::: " + e.getMessage());
e.printStackTrace();
return 0;
}
}

Exception :

org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [${getKycComplinedCustomerRowsNonIndividual]; Parameter index out of range (1 > number of parameters, which is 0).; nested exception is java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).

最佳答案

我发现了这个bug,实际上,我没有为变量getCustomerRows正确设置值到@Value注释,@Value中缺少右花括号注释给出(在本例中)java.sql.SQLException: Parameter index out of range. Exception

关于mysql - 使用 queryForObject() 方法检索计数时,JDBCTemplate 中的参数索引超出范围(1 > 参数数量,即 0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52974064/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com