Current specdiffs for JDBC 4.2
Lance Andersen - Oracle
Lance.Andersen at oracle.com
Tue Dec 18 11:41:10 PST 2012
On Dec 18, 2012, at 2:35 PM, Mark Rotteveel wrote:
> On 18-12-2012 20:18, Mark Rotteveel wrote:
>> http://cr.openjdk.java.net/~lancea/8005080/specdiffs.00/java/sql/DatabaseMetaData-report.html#method:supportsRefCursors()
>>
>> What are REF CURSORs, and what are the semantics of a REF CURSOR; is
>> this purely a change to support the Oracle concept of ref cursor, or are
>> there other databases that support this (or a similar) concept (if so
>> which databases)?
See below, multiple drivers support this differently which is why we are adding a consistent view.
---------------------------------------------
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;
}
>
> I also didn't actually seem to find anything else in the API that exposes REF CURSOR (eg a specific getter (or setter?) in ResultSet or CallableStatement), nor did I find an interface for it. Is there actually anything exposing REF CURSOR in the API?
>
> Mark
> --
> Mark Rotteveel
-------------- next part --------------
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