Adding REF CURSOR support for CallableStatements
Lance Andersen - Oracle
Lance.Andersen at oracle.com
Wed Nov 14 04:27:13 PST 2012
Attached are the JDBC 4.2 changes for standardizing REF CURSOR support.
Best
Lance
---------------------------------------------
13.3.3.4 REF CURSOR Support
The REF CURSOR data type is supported by several databases. To return a REF CURSOR from a stored procedure, the CallableStatement method registerOutParameter
may be used specifying Types.REF_CURSOR as the data type to be returned. The CallableStatement method getObject, specifying ResultSet as the type to convert the returned object to,
would be called to retrieve the ResultSet representing the REF CURSOR. The returned result set is a forward, read-only result set.
if registerOutParameter is called specifying Types.REF_CURSOR and the JDBC driver does not support this data type, a SQLFeatureNotSupportedException will be thrown.
CallableStatement cstmt = conn.prepareCall(" { call mySproc(?) }");
cstmt.registerOutParameter(1, Types.REF_CURSOR);
cstmt.executeQuery();
ResultSet rs = cstmt.getObject(1, ResultSet.class);
while (rs.next ()) {
System.out.println("Name="+ rs.getString(1));
}
code example 13-28 Executing a callable statement that returns a ResultSet using a REF CURSOR
To determine if a JDBC Driver supports REF CURSOR, an application may call DatabaseMetaData.supportsRefCursors.
interface DatabaseMetaData {
/**
* Retrieves whether this database supports REF CURSOR.
*
* @return {@code true} if this database supports REF CURSOR;
* {@code false} otherwise
* @exception SQLException if a database access error occurs
* @since 1.8
*/
boolean supportsRefCursors() throws SQLException;
}
The entry in Types.java
public class Types {
/**
* The constant in the Java programming language, sometimes referred to
* as a type code, that identifies the generic SQL type {@code REF CURSOR}.
*
* @since 1.8
*/
public static final int REF_CURSOR = 2012;
}
Lance Andersen| Principal Member of Technical Staff | +1.781.442.2037
Oracle Java Engineering
1 Network Drive
Burlington, MA 01803
Lance.Andersen at oracle.com
More information about the jdbc-spec-discuss
mailing list