java调用存储过程(返回游标变量,利用索引表,临时表)

/*创建临时表及存储过程*/

Create Global Temporary Table test1
(name varchar2(20),age int)
On Commit Delete Rows;

create or replace package addnum
is
  type emp_table_type is table of varchar2(200)
  index by binary_integer;
  type emp_cur is ref cursor;
end;
/

create or replace procedure test2
(abc in out addnum.emp_table_type)
is
begin
   abc(0) := 'aaaaa';
   abc(1) := 20;
   abc(3) := 'bbbbb';
   abc(4) := 30;
end;
/
create or replace procedure test3
(ccc in out addnum.emp_cur)
is
   cba addnum.emp_table_type;
begin
   test2(cba);
   insert into test1 values(cba(0),cba(1));
   insert into test1 values(cba(3),cba(4));
end;
/


create or replace procedure test4
(e_cur in out addnum.emp_cur)
is
begin
   test3(e_cur);
   open e_cur for select * from test1;
end;
/

 

 

 

 

 

/*java调用*/

  Connection conn = DaoUtil.getConnection();
  conn.setAutoCommit(false);
  
  CallableStatement call = conn.prepareCall("call test4(?)");
  call.registerOutParameter(1, OracleTypes.CURSOR);
  call.execute();
  ResultSet rs = (ResultSet) call.getObject(1); 
  while(rs.next()){
   System.out.println(rs.getString(1) + "," + rs.getInt(2));
  }
  conn.commit();
  rs.close();
  call.close();
  conn.close();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值