一,当存储过程返回游标类型时:
存储过程内容如下:
create or replace procedure pro_getcurtaskinfobytimeandid(taskId in varchar2,curTime in varchar2,rst out sys_refcursor)
is
begin
open rst for
select * from ( select * from disa_rescue_task_history
where task_id = taskId
and record_time >= to_date(curTime,'yyyy-mm-dd hh24:mi:ss') order by record_time ) where rownum = 1;
end pro_getcurtaskinfobytimeandid;
这时,java调用如下:
package test;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import oracle.jdbc.driver.OracleTypes;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.CallableStatementCallback;
import org.springframework.jdbc.core.CallableStatementCreator;
import com.supermap.earth.rims.util.SprintHelper;
import com.supermap.earth.server.base.dao.SpringJdbcUtil;
public class Test {
public static void main(String[] args)throws Exception {
SpringJdbcUtil springJdbcUtil= (SpringJdbcUtil)SprintHelper.getInstance().getBean("springJdbcUtil");
List resultList = (List) springJdbcUtil.getJdbcTemplate().execute(
new CallableStatementCreator() {
public CallableStatement createCallableStatement(Connection con) throws SQLException {
String storedProc = "{ call pro_getcurtaskinfobytimeandid(?,?,?) }";// 调用的sql
CallableStatement cs = con.prepareCall(storedProc);
cs.setString(1, "8a5fec0257954c798a94e86a2c60f680");// 设置输入参数的值
cs.setString(2, "2013-1-27 15:54:32");// 设置输入参数的值
</