1, 建一个程序包。如下: CREATE OR REPLACE PACKAGE TESTPACKAGE AS TYPE Test_CURSOR IS REF CURSOR; end TESTPACKAGE; 2,建立存储过程,存储过程为: CREATE OR REPLACE PROCEDURE TESTC(p_CURSOR out TESTPACKAGE.Test_CURSOR) IS BEGIN OPEN p_CURSOR FOR SELECT * FROM tablename; END TESTC; 调用: Class.forName(driver); conn = DriverManager.getConnection(strUrl, "hyq", "hyq"); CallableStatement proc = null; proc = conn.prepareCall("{ call hyq.testc(?) }"); proc.registerOutParameter(1,oracle.jdbc.OracleTypes.CURSOR); proc.execute(); rs = (ResultSet)proc.getObject(1); while(rs.next()) { ··· }
CREATE OR REPLACE PACKAGE TESTPACKAGE AS
TYPE Test_CURSOR IS REF CURSOR;
end TESTPACKAGE;
2,建立存储过程,存储过程为:
CREATE OR REPLACE PROCEDURE TESTC(p_CURSOR out TESTPACKAGE.Test_CURSOR) IS
BEGIN
OPEN p_CURSOR FOR SELECT * FROM tablename;
END TESTC;
调用:
Class.forName(driver);
conn = DriverManager.getConnection(strUrl, "hyq", "hyq"); CallableStatement proc = null;
proc = conn.prepareCall("{ call hyq.testc(?) }");
proc.registerOutParameter(1,oracle.jdbc.OracleTypes.CURSOR);
proc.execute();
rs = (ResultSet)proc.getObject(1); while(rs.next())
{
···
}