Use DB2CachedRowSet

Because the DB2CachedRowSet object can be disconnected and serialized, it is useful in environments where it is not always practical to run a full JDBC driver (for example, on Personal Digital Assistants (PDAs) and Java-enabled cell phones).

Since the DB2CachedRowSet object is contained in memory and its data is always known, it can serve as a highly optimized form of a scrollable ResultSet for applications. Whereas DB2ResultSets that are scrollable typically pay a performance penalty because their random movements interfere with the JDBC driver's ability to cache rows of data, RowSets do not have this issue.

Two methods are provided on DB2CachedRowSet that create new RowSets:

You can use the createCopy method to hand out common ResultSets to clients. If the table data is not changing, creating a copy of a RowSet and passing it to each client is more efficient than running a query against the database each time.

You can use the createShared method to improve your database's performance by allowing several people to use the same data. For example, assume that you have a Web site that shows the top twenty best-selling products on your home page when a customer connects. You want the information on your main page to be updated regularly, but running the query to get the most frequently purchased items every time a customer visits your main page is not practical. Using the createShared method, you can effectively create "cursors" for each customer without having to either process the query again or store an enormous amount of information in memory. When appropriate, the query to find the most frequently purchased products can be run again. The new data can populate the RowSet that is used to create the shared cursors and the servlets can use them.

DB2CachedRowSets provide a delayed processing feature. This feature allows multiple query requests to be grouped together and processed against the database as a single request. This is an example of using DB2CachedRowSets to eliminate some of the computational stress that the database would otherwise be under.

Because the RowSet must keep careful track of any changes that happen to it so that they are reflected back to the database, there is support for functions that undo changes or allow you to see all changes have been made. For example, there is a showDeleted method that can be used to tell the RowSet to let you fetch deleted rows. There are also cancelRowInsert and cancelRowDelete methods to undo row insertions and deletions, respectfully, after they have been made.

The DB2CachedRowSet object offers better interoperability with other Java™ APIs because of its event handling support and its toCollection methods that allow a RowSet or a portion of it to be converted into a Java collection.

The event handling support of DB2CachedRowSet can be used in graphical user interface (GUI) applications to control displays, for logging information about changes to the RowSet as they are made, or to find information about changes to sources other than RowSets. See Example: DB2JdbcRowSet events for details.

For specific details on working with DB2CachedRowSets, see the following topics:

For information on the event model and event handling, see DB2JdbcRowSet as this support works identically for both types of RowSets.

Related concepts
Other DB2CachedRowSet features
Related reference
Create and populate a DB2CachedRowSet
Access DB2CachedRowSet data and cursor manipulation
Change DB2CachedRowSet data and reflect changes back to the data source