DB2 Version 9.7 for Linux, UNIX, and Windows

ROWIDs in JDBC with the IBM Data Server Driver for JDBC and SQLJ

DB2® for z/OS® and DB2 for i support the ROWID data type for a column in a database table. A ROWID is a value that uniquely identifies a row in a table.

Although IBM® Informix® also supports rowids, those rowids have the INTEGER data type. You can select an IBM Informix rowid column into a variable with a four-byte integer data type.

You can use the following ResultSet methods to retrieve data from a ROWID column:
You can use the following ResultSet method to update a ROWID column of an updatable ResultSet:

If you are using JDBC 3.0, for getObject, the IBM Data Server Driver for JDBC and SQLJ returns an instance of the IBM Data Server Driver for JDBC and SQLJ-only class com.ibm.db2.jcc.DB2RowID.

If you are using JDBC 4.0, for getObject, the IBM Data Server Driver for JDBC and SQLJ returns an instance of the class java.sql.RowId.

You can use the following PreparedStatement methods to set a value for a parameter that is associated with a ROWID column:

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:

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.
Table 1. DatabaseMetaData.getRowIdLifetime values for supported data sources
Database server DatabaseMetaData.getRowIdLifetime
DB2 for z/OS ROWID_VALID_TRANSACTION
DB2 for Linux, UNIX, and Windows ROWID_UNSUPPORTED
DB2 for i ROWID_VALID_FOREVER
IBM Informix ROWID_VALID_FOREVER
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)