Java:如何将Spring RowMapper与CallableStatement一起用于存储过程?
我使用CallableStatement调用存储过程,如下所示:Java:如何将Spring RowMapper与CallableStatement一起用于存储过程?,java,jdbctemplate,callable-statement,Java,Jdbctemplate,Callable Statement,我使用CallableStatement调用存储过程,如下所示: Connection connection = jdbcTemplate.getDataSource().getConnection(); CallableStatement callSt = connection.prepareCall("{call my_proc(?, ?)}"); callSt.setDate(1, getDate()); callSt.registerOutParameter(2, oracle.jdbc
Connection connection = jdbcTemplate.getDataSource().getConnection();
CallableStatement callSt = connection.prepareCall("{call my_proc(?, ?)}");
callSt.setDate(1, getDate());
callSt.registerOutParameter(2, oracle.jdbc.OracleTypes.CURSOR);
callSt.execute();
ResultSet rs = (ResultSet) callSt.getObject(2);
然后,我迭代结果集以创建一个包含4到5项的列表
我的问题是如何避免迭代ResultSet并使用RowMapper获取列表
附言:
我发现了使用SimpleJDBCall使用mapper的另一种方法
SimpleJdbcCall call = new SimpleJdbcCall(jdbcTemplate)
.withSchemaName("myindex")
.withCatalogName("mypackage")
.withProcedureName("my_proc")
.declareParameters(new SqlParameter[]{
new SqlParameter("myinput", OracleTypes.DATE),
new SqlOutParameter("myoutput", OracleTypes.CURSOR, new MyMapper())
});
请参阅感谢您提供的链接,但我不喜欢jdbcTemplate.query()的概念。我要通过CallableStatement来完成。实际上,我得到了使用mapper的另一种方法(更新的问题),请参见感谢您提供的链接,但我不喜欢jdbcTemplate.query()的想法。我要通过CallableStatement来完成。我实际上得到了使用mapper的另一种方法(更新的问题)