jdbc调用存储过程oracle版 返回游标

1.创建

复制代码
1 create or replace procedure getLog(record_ref out sys_refcursor,inputId in log201112.id%type)
2 AS
3 begin
4 open record_ref for
5     select * from log201112 where id=inputId;
6 end getLog;
7 /
复制代码

2.调用

 1 String procedure="{call getLog(?,?)}";
 2   CallableStatement cstmt=conn.prepareCall(procedure);//conn为java.sql.Connection对象
 3   cstmt.registerOutParameter(1, OracleTypes.CURSOR);//oracle驱动包里的类 import oracle.jdbc.OracleTypes;
 4   cstmt.setInt(2, 2);
 5   cstmt.execute();
 6   ResultSet rs=(ResultSet)cstmt.getObject(1);
 7   while(rs.next()){
 8       String info=""+rs.getInt("ID");
 9       info+=rs.getTimestamp("CREATE_TIME");
10       System.out.println(info);
11    }
原文地址:https://www.cnblogs.com/huzi007/p/2874499.html