Distinct Types In Jdbc Applications - IBM DB2 Manual

Table of Contents

Advertisement

If you are using JDBC 3.0, for setObject, use the IBM Data Server Driver for JDBC
and SQLJ-only type com.ibm.db2.jcc.Types.ROWID or an instance of the
com.ibm.db2.jcc.DB2RowID class as the target type for the parameter.
If you are using JDBC 4.0, for setObject, use the type java.sql.Types.RowId or an
instance of the java.sql.ROWID class as the target type for the parameter.
You can use the following CallableStatement methods to retrieve a ROWID
column as an output parameter from a stored procedure call:
v getRowId (JDBC 4.0 and later)
v getObject
To call a stored procedure that is defined with a ROWID output parameter, register
that parameter to be of the java.sql.Types.ROWID type.
ROWID values are valid for different periods of time, depending on the data
source on which those ROWID values are defined. Use the
DatabaseMetaData.getRowIdLifetime method to determine the time period for
which a ROWID value is valid. The values that are returned for the data sources
are listed in the following table.
Example: Using PreparedStatement.setRowId with a java.sql.RowId target type: Suppose
that rwid is a RowId object. To set parameter 1, use this form of the setRowId
method:
ps.setRowId(1, rid);
Example: Using ResultSet.getRowId to retrieve a ROWID value from a data source: To
retrieve a ROWID value from the first column of a result set into RowId object
rwid, use this form of the ResultSet.getRowId method:
java.sql.RowId rwid = rs.getRowId(1);
Example: Using CallableStatement.registerOutParameter with a java.sql.Types.ROWID
parameter type: To register parameter 1 of a CALL statement as a
java.sql.Types.ROWID data type, use this form of the registerOutParameter
method:
cs.registerOutParameter(1, java.sql.Types.ROWID)

Distinct types in JDBC applications

A distinct type is a user-defined data type that is internally represented as a
built-in SQL data type. You create a distinct type by executing the SQL statement
CREATE DISTINCT TYPE.
56
Application Programming Guide and Reference for Java
Table 9. DatabaseMetaData.getRowIdLifetime values for supported data sources
Database server
DB2 for z/OS
DB2 Database for Linux, UNIX, and Windows
DB2 for i5/OS
IDS
Related reference
"Data types that map to database data types in Java applications" on page 193
"DB2RowID interface" on page 352
DatabaseMetaData.getRowIdLifetime
ROWID_VALID_TRANSACTION
ROWID_UNSUPPORTED
ROWID_VALID_FOREVER
ROWID_VALID_FOREVER

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents