我正在尝试使用Springs的NamedParameterJdbcTemplate来调用具有两个具有设置值的输入参数的Oracle存储过程,并且存储过程返回具有多个列/行的8个游标。我能够使用Spring的SimpleJdbcCall使用以下代码调用存储过程(敏感信息已被更改):
SqlParameter con_num = new SqlParameter("con_num",12); //12 is VARCHAR TYPE
SqlParameterValue con_num2 = new SqlParameterValue(con_num, "859999");
SqlParameter in_date = new SqlParameter("in_date",12);
SqlParameterValue in_date2 = new SqlParameterValue(in_date, "20160628");
SqlOutParameter account_cur = new SqlOutParameter("account_cur", -10); //-10 is ORACLE CURSOR TYPE
SqlOutParameter fund_cur = new SqlOutParameter("fund_cur", -10);
SqlOutParameter notes_cur = new SqlOutParameter("notes_cur", -10);
SqlOutParameter withdrawal_cur = new SqlOutParameter("withdrawal_cur", -10);
SqlOutParameter contract_cur = new SqlOutParameter("contract_cur", -10);
SqlOutParameter pin_cur = new SqlOutParameter("pin_cur",-10);
SqlOutParameter alert_cur = new SqlOutParameter("alert_cur", -10);
SqlOutParameter rider_cur = new SqlOutParameter("rider_cur",-10);
ColumnMapRowMapper [] columnMapRowMapperArray = new ColumnMapRowMapper[8];
for(int x =0; x<=7; x++)
{
columnMapRowMapperArray[x] = new ColumnMapRowMapper();
}
SimpleJdbcCall sp = new SimpleJdbcCall(dataSource)
.withSchemaName("SCHEMA")
.withCatalogName("CATALOG")
.withProcedureName("StoredProc1")
.withoutProcedureColumnMetaDataAccess()
.returningResultSet("account_cur", columnMapRowMapperArray[0])
.returningResultSet("fund_cur", columnMapRowMapperArray[1])
.returningResultSet("notes_cur", columnMapRowMapperArray[2])
.returningResultSet("withdrawal_cur", columnMapRowMapperArray[3])
.returningResultSet("contract_cur", columnMapRowMapperArray[4])
.returningResultSet("pin_cur", columnMapRowMapperArray[5])
.returningResultSet("alert_cur", columnMapRowMapperArray[6])
.returningResultSet("rider_cur", columnMapRowMapperArray[7])
.declareParameters(con_num2, in_date2,account_cur,fund_cur,
notes_cur,withdrawal_cur,contract_cur,
pin_cur,alert_cur,rider_cur);
但我无法弄清楚如何使用NamedParamaterJDBC调用它...我一直在
SQL状态[99999];错误代码[17004];
列类型无效;
嵌套异常是java.sql.SQLException:列类型无效
String storedProc = "call SCHEMA.CATALOG.STOREDPROC1(:CON_NUM,:IN_DATE,ACCOUNT_CUR=>:ACCOUNT_CUR,FUND_CUR=>:FUND_CUR,NOTES_CUR=>:NOTES_CUR,WITHDRAWAL_CUR=>:WITHDRAWAL_CUR,CONTRACT_CUR=>:CONTRACT_CUR,PIN_CUR=>:PIN_CUR,ALERT_CUR=>:ALERT_CUR,RIDER_CUR=>:RIDER_CUR";
ColumnMapRowMapper[] columnMapRowMapperArray = new ColumnMapRowMapper[8];
for (int x = 0; x <= 7; x++) {
columnMapRowMapperArray[x] = new ColumnMapRowMapper();
}
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("CON_NUM", "859999",12)
.addValue("IN_DATE","20160628",12)
.addValue("ACCOUNT_CUR", columnMapRowMapperArray[0],-10)
.addValue("FUND_CUR",columnMapRowMapperArray[1],-10)
.addValue("NOTES_CUR",columnMapRowMapperArray[2],-10 )
.addValue("WITHDRAWAL_CUR",columnMapRowMapperArray[3],-10)
.addValue("CONTRACT_CUR",columnMapRowMapperArray[4],-10)
.addValue("PIN_CUR",columnMapRowMapperArray[5],-10)
.addValue("ALERT_CUR",columnMapRowMapperArray[6],-10)
.addValue("RIDER_CUR",columnMapRowMapperArray[7],-10);
NamedParameterJdbcTemplate npt = new NamedParameterJdbcTemplate(dataSource);
List<Map<String, Object>> result = npt.queryForList(storedProc, params);
非常感谢任何帮助!