Posted by lancea
on March 10, 2006 at 3:32 PM PST
JDBC 4.0 has introduced several new features which will be highlighted in blogs over the next few weeks. Today's focus is on the RowId interface.
The RowID interface was added to JDBC 4.0 in order to support the ROWID datatype which is supported by databases such as Oracle and DB2. A ROWID may be thought of as the address for a given row within a table and maybe be considered either logical or physical depending on the underlying data source.
The lifetime of a RowId object may be valid as long as the row is not deleted and the lifetime of the RowId is within the bounds of the lifetime of the RowId's data source.
The DatabaseMetaDataMethod.getRowIdLifetime() can be used to
determine the lifetime validity of the RowId object. The return value from this method is a RowIdLifetime enumerated data-type. Possible values are:
- ROWID_UNSUPPORTED - backend does not support RowIds
- ROWID_VALID_OTHER - lifetime of the RowId is implementation dependant
- ROWID_VALID_TRANSACTION - lifetime of the RowId is within the transaction as long as the row is not deleted
- ROWID_VALID_SESSION - the lifetime of the RowId is as long as the session as long as the row is not deleted
- ROWID_VALID_FOREVER - the lifetime of the RowId is unlimited as long as the row is not deleted
You can obtain a ROWID using the ResultSet.getRowId() method and may use the PreparedStatement.setRowId() to use a RowId in query.
A RowId object value is typically not portable between data sources and should be considered as specific to the data source when using the set or update method in PreparedStatement and ResultSet objects respectively. It is therefore inadvisable to get a RowId from a ResultSet object with a connection