package test.sqlj;import oracle.sqlj.runtime.Oracle;
import java.sql.SQLException;public class StoreProc{
  public static void main(String args[]){
    try{
     try{
        Oracle.connect("jdbc:oracle:oci8:@DATABASE","username","password",true);        // initialize bind variables
Integer studentid = new Integer(100);
String studentname = "test_user";
String studentstreet = "test_address";
String studentcity = "test_city"; #sql{CALL insertstudent(:IN(studentid),
:IN(studentname),
:IN(studentstreet),
:IN(studentcity))}; // reset variables
Integer holderInt = new Integer(studentid.intValue());
studentid = new Integer(0);
studentname = "";
studentstreet = "";
studentcity = ""; //retrieving the values the stored procedure just inserted
#sql {SELECT student_id,stu_name,street,city
      INTO 
:OUT(studentid),
:OUT(studentname),
:OUT(studentstreet),
:OUT(studentcity)
      FROM
student
      WHERE
student_id=:IN(holderInt)};
 } catch(Exception e) {
System.out.println(e.toString());
} finally {
   Oracle.close();
}
    } catch(SQLException sqe) {
System.out.println("Error closing the database connection: " + sqe.toString());
    }
   }
  }

解决方案 »

  1.   

    create or replace procedure prc_Test_refcursor(v_refcur out PKG_RefCursor.Refcursor) is
      strsql varchar2(200);
      V_SYSDATE DATE;
    begin
      strsql:='select sysdate from DUAL';
      open v_refcur for strsql;
      --CLOSE V_REFCUR;
      --DBMS_OUTPUT.put_line(TO_CHAR(V_SYSDATE,'YYYY-MM-DD'));
    end prc_Test_refcursor;
    create or replace procedure p_test_refcur is
    v_refcur  PKG_RefCursor.Refcursor;
    begin
      prc_Test_refcursor(v_refcur);
    end p_test_refcur;