【发布时间】:2023-03-22 11:15:01
【问题描述】:
我正在尝试使用 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;
}
}
例外:
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).
【问题讨论】:
标签: mysql spring-mvc prepared-statement jdbctemplate