日期:2014-05-16  浏览次数:20476 次

java调用返回为游类型的存储过程
/*java 部分*/
mport java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Test1 {

public static void main(String[] args) {

Connection cn =new  ConnectionDataBase().createConnection();
String sql = "{call mypac.cur_pro(?)}";
try {
CallableStatement cst= cn.prepareCall(sql);
//注册输出  如果是输如 cst.setString(第几个问号,设定的值);
cst.registerOutParameter(1,oracle.jdbc.OracleTypes.CURSOR);
cst.executeQuery();
ResultSet rs =(ResultSet) cst.getObject(1);
while(rs.next()){
System.out.println(rs.getString(1)+":"+rs.getString(2));
}
} catch (SQLException e) {
e.printStackTrace();
}

}



}

/*数据库部分*/

-------------------------------------------------任务写一个返回参数为动态游标存储过程
--注意包头是定义规范,包体实现包头所有的存储过程和函数
create or replace package mypac is

procedure cur_pro (mycursor out sys_refcursor);


end mypac;

create or replace package body mypac is
 
       procedure cur_pro ( mycursor out sys_refcursor )
         is
    
      begin
 
      open mycursor for select *from emp;
  
    end cur_pro;
end mypac;