您的位置:首页 > 数据库 > Oracle

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

2011-12-20 11:04 531 查看
1.创建

create or replace procedure getLog(record_ref out sys_refcursor,inputId in log201112.id%type)
AS
begin
open record_ref for
select * from log201112 where id=inputId;
end getLog;
/


2.调用

String procedure="{call getLog(?,?)}";
CallableStatement cstmt=conn.prepareCall(procedure);//conn为java.sql.Connection对象
cstmt.registerOutParameter(1, OracleTypes.CURSOR);//oracle驱动包里的类 import oracle.jdbc.OracleTypes;
cstmt.setInt(2, 2);
cstmt.execute();
ResultSet rs=(ResultSet)cstmt.getObject(1);
while(rs.next()){
String info=""+rs.getInt("ID");
info+=rs.getTimestamp("CREATE_TIME");
System.out.println(info);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: