Oracle's Plsql
CREATE OR REPLACE Package chapter_13 as
TYPE RS is REF CURSOR;
Procedure founder (ofields out RS);
End
CREATE OR REPLACE Package Body chapter_13 as
PROCEDURE founder (Ofields out RS) is
BEGIN
Open Ofields for
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.execute ();
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 ();
}
}