首页 > 解决方案 > 异常参数索引超出范围:Java 中使用 Spring Batch ItemReader 时为 0

问题描述

我正在创建一个 Spring Batch Job,其 Item Reader 的定义如下:

StoredProcedureItemReader<GenData> spir = new StoredProcedureItemReader<GenData>();

//Sybase data source specified
spir.setDataSource(ds1);

//Sybase stored proc : exec procedure_name
spir.setProcedureName(proc1);

spir.setRowMapper(objectRowMapper());

其中 objectRowMapper 是:

private RowMapper<GenData> objectRowMapper() {
   return new RowMapper<GenData>() {

   @Override
   public GenData mapRow(ResultSet rs, int rowNum) throws SQLException {
      GenData gdo = new GenData();
      ResultSetMetaData rsmd = rs.getMetaData();
      int columnCount = rsmd.getColumnCount();
      ArrayList<String> colNames = new ArrayList<String>();

      for(int i = 1; i <= columnCount; i++) {
          String name = rsmd.getColumnName(i);
          colNames.add(name);
          //object has a map where we put the <columnName, columnValue>
          //these are supposed to be dynamic in the code hence made like this
          gdo.objectData.put(name, rs.getString(name));
       }
      return gdp;
   }
}

上面的代码抛出错误: 执行存储过程;JZ0SB:参数索引超出范围:0;嵌套异常是 java.sql.SQLException:JZ0SB:Paramater index out of range: 0

有人可以告诉这是什么意思。尤其是最后的数字 0,因为它似乎是这里最大的线索。

谢谢!!

标签: springjdbcspring-batchsybasespring-jdbc

解决方案


推荐阅读