Source: Network/Editor: getting started with programming: Unknown
Oracle PLSQL
Create or replace package chapter_13
Type RS is ref cursor;
Procedure founder (ofields out Rs );
End;
Create or replace package body chapter_13
Procedure founder (ofields out Rs) is
Begin
Open ofields
Select * From person;
End founder;
End;
Java code
Package JDBC;
Import java. Io .*;
Import java. SQL .*;
Import java. Text .*;
Import oracle. JDBC. oracletypes;
Public class teststoredprocedures {
Connection conn;
Public teststoredprocedures (){
Try {
Drivermanager. registerdriver (New Oracle. JDBC. Driver. oracledriver ());
Conn = drivermanager. getconnection (
"JDBC: oracle: thin: @ localhost: 1521: orcl", "Jola", "Jola ");
} Catch (sqlexception e ){
System. Err. println (E. getmessage ());
E. printstacktrace ();
}
}
Public static void main (string [] ARGs) throws exception {
New teststoredprocedures (). Process ();
}
Public void process () throws sqlexception {
Long start = 0;
Long end = 0;
Callablestatement cstmt = NULL;
Try {
Start = system. currenttimemillis ();
// *** Sql92 escape syntax ***
Cstmt = conn. preparecall (
"{Call chapter_13.founder (?)} ");
Cstmt. registeroutparameter (1, oracletypes. cursor );
Resultset rs = NULL;
Cstmt.exe cute ();
Rs = (resultset) cstmt. GetObject (1 );
While (Rs. Next ()){
System. Out. println (Rs. getstring ("name "));
}
Rs. Close ();
End = system. currenttimemillis ();
System. Out. println ("average elapsed time =" +
(End-Start)/8 + "milliseconds ");
} Catch (sqlexception e ){
System. Err. println ("SQL error:" + E. getmessage ());
} Finally {
If (cstmt! = NULL ){
Try {
Cstmt. Close ();
} Catch (sqlexception ignore ){}
}
}
}
Protected void finalize () throws throwable {
If (Conn! = NULL ){
Try {
Conn. Close ();
} Catch (sqlexception ignore ){}
}
Super. Finalize ();
}
}