JDBC code to access a REFCURSOR.

Java Primer
A JSP Architecture for Oracle Stored Procedures
by Satya Komatineni
Listing 1. JDBC code to access a REFCURSOR.


// Specify your stored procedure
// '?' is a place holder for REFCURSOR variable
CallableStatement stmt = con.prepareCall(
        "{call pkg_book_info.SpGetAuthors(?)}");

// Bind the '?', the first argument, to an Oracle CURSOR
stmt.registerOutParameter(1,OracleTypes.CURSOR);
stmt.execute();

// Type cast the return to a ResultSet
ResultSet rs = (ResultSet)stmt.getObject(1);

// process the result set as usual after that
.......
finally
{
    if (rs != null) rs.close();
    if (stmt != null) stmt.close();
    if (con !=null) con.close();
}

Featured

Most   Popular
Upcoming Events

AppTrends

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.