【问题标题】:Parameter index out of range (1 > number of parameters, which is 0) in JDBCTemplate while retrieving count from with queryForObject() method使用 queryForObject() 方法检索计数时,JDBCTemplate 中的参数索引超出范围(1 > 参数数,即 0)
【发布时间】: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


    【解决方案1】:

    我发现了这个错误,实际上,我没有为变量getCustomerRows 正确设置@Value 注释的值,@Value 注释中缺少一个右花括号,它给出(在这种情况下)java.sql.SQLException: Parameter index out of range.例外

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-29
      • 1970-01-01
      • 1970-01-01
      • 2017-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多