Java Reference
In-Depth Information
Storing Results in a RowSet
Problem
You need to save some results in a JDBC form without maintaining a database connection.
Or you want some JDBC results to have JavaBean semantics.
Solution
Use a RowSet —in particular, a CachedRowSet .
Discussion
The RowSet interface, a subinterface of ResultSet , was introduced with JDBC 2 and up-
dated in JDBC 4.1 (with JavaSE 7). Because a RowSet is a ResultSet , you can use any of
the ResultSet processing methods previously discussed. But RowSet s tend to be more self-
contained; you typically do not need to specify a driver, and performing queries is done in a
new way. You call setCommand() to specify the query and execute() to perform the query
(this takes the place of creating a Statement and calling its executeQuery() method).
The five subinterfaces are listed in Table 18-4 . For each of these, a reference implementation
is provided in the com.sun.rowset package.
Table 18-4. RowSet subinterfaces
Interface
name
RowSetFactory Meth-
od
Purpose
Caches results in memory; disconnected Rowset
CachedRowSet
createCachedRowSet
Implements lightweight querying, using
javax.sql.rowset.Predicate
FilteredRowSet
createFilteredRowSet
Makes results available as a JavaBean component
JdbcRowSet
createJdbcRowSet
Combine multiple RowSet s into one, like an SQL join
JoinRowSet
createJoinRowSet
Convert between XML data and RowSet
WebRowSet
createWebRowSet
Search WWH ::




Custom Search