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 @ 2013-01-24 10:57  全力以赴001  阅读(2309)  评论(0编辑  收藏  举报