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 }



posted @ 2011-12-20 11:04  tazi  阅读(337)  评论(0编辑  收藏  举报