Previous Topic: Scrollable Result SetsNext Topic: CA IDMS Result Sets


JDBC Result Sets and Row Sets

The JDBC java.sql.ResultSet interface defines an object used to manipulate an SQL cursor. It provides methods to position the cursor, access columns within the current row, and update values in the table.

The type attribute indicates how the current row is positioned for the result set, whether it is scrollable or not, and the visibility of changes made by other transactions or cursors. There are three types:

TYPE_FORWARD_ONLY—the cursor can only move forward.

TYPE_SCROLL_INSENSITIVE—the cursor can move forward, backward, or to a specific row. The values in the result set are fixed when the cursor is opened or the rows are first retrieved, depending on the database implementation, and do not generally reflect changes made by other transactions.

TYPE_SCROLL_SENSITIVE—the cursor can move forward, backward, or to a specific row. The values in result set generally do reflect changes made by other transactions.

The concurrency attribute indicates if the result set is updateable. An updateable result set provides methods that can be used to change values in the table, and is an alternative to using SQL positioned update statements. There are two concurrency options:

CONCUR_READ_ONLY—the current row cannot be updated directly.

CONCUR_UPDATABLE—the current row can be updated using JDBC methods instead of SQL statements.

These attributes are independent, which means there are six possible combinations.

A JDBC driver provides an implementation of the ResultSet interface. At a minimum a driver must support a forward only, read only result set. Any additional capabilities are optional.

The JDBC javax.sql.RowSet interface extends the ResultSet interface with methods that support the JavaBeans component model. The javax.sql.rowset package includes a set of specialized row set interfaces that provide additional capabilities. These include the javax.sql.rowset.JdbcRowSet, wraps a JDBC ResultSet and maintains a connection to the database, and the javax.sql.rowset.CachedRowSet, which caches column values and can be disconnected from the database.

Row sets are designed to be implemented on top of the JDBC methods, and JDBC drivers are not required to implement them. A row set implementation can support type and concurrency options beyond those supported by the JDBC drivers result set implementation. Starting with Java 1.5, the Java Run Time Environment (JRE) includes a Reference Implementation (RI) of the javax.sql.rowset package.

The JDBC API documentation (javadoc) contains detailed descriptions of the classes and methods that support this feature. The JDBC Specification also contains examples of how an application would use a scrollable or updateable result set.