当前位置: 代码迷 >> 高性能WEB开发 >> jdbcTemplate调用存储过程的有关问题
  详细解决方案

jdbcTemplate调用存储过程的有关问题

热度:385   发布时间:2012-03-22 17:43:57.0
jdbcTemplate调用存储过程的问题
请教高手,有用spring 的jdbcTemplate调用存储过程的没有?
我调用存储过程时参数可以返回,但是结果集却不能返回,是什么原因?

部分代码:
public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {  
cs.setInt(2,int_pageNumber);
cs.setInt(3,int_currentPage);
cs.setString(4,hql.toString());
cs.registerOutParameter(1, Types.INTEGER);  
ResultSet rs = cs.executeQuery();
int totalCount = cs.getInt(1);
System.out.println("totalCount::"+totalCount);
System.out.println("ddd:"+rs.getRow());

第一句输出没问题,第二输出的记录数就是0了

存储过程中是用exec sp_executesql执行的查询语句,这个是没有问题的

请问高手们,可能出现的问题在哪?

------解决方案--------------------
jdbcTemplaate.execute()方法,实现两个接口CallableStatementCreator和CallableStatementCallback
实现接口CallableStatementCreator的类中 
cs = conn.prepareCall(storedProcName.toString());
cs.registerOutParameter(1, OracleTypes.CURSOR); --定义的第一个参数是游标
cs.setObject(2, params);--定义的第二个参数是要传进去的值

在你的doInCallableStatement方法中,
cs.execute();
ResultSet rs = (ResultSet) cs.getObject(1);

取到ResultSet ,剩下的你会了吧。
  相关解决方案