spring jdbctemplate或jdbc调用返回游标或复杂数据类型的存储过程

本文介绍了如何使用Spring JDBC模板或直接的Java JDBC调用返回游标和复杂自定义类型数据的Oracle存储过程。示例包括设置输入参数,注册输出参数为游标类型,并解析返回的ResultSet。对于返回复杂类型的存储过程,文章展示了如何处理Oracle的自定义对象和集合类型,将数据转换为Java对象。
摘要由CSDN通过智能技术生成

一,当存储过程返回游标类型时:

存储过程内容如下:

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");// 设置输入参数的值    
</

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值