Java Reference
In-Depth Information
}
}
Running this example code will display output that looks similar to the following
code, although the text might vary depending on the values in the database. Notice that
the database record for Recipe 13-2 has a changed description after the update of the
CachedRowSet .
Successfully connected
13-1: Connecting to a Database - DriverManager and
DataSource Implementations - More to Come
13-2: Querying a Database and Retrieving Results
- Subject to Change
13-3: Handling SQL Exceptions - Using SQLException
Updating Recipe 13-2
13-1: Connecting to a Database - DriverManager and
DataSource Implementations - More to Come
13-2: Querying a Database and Retrieving Results
- Obtaining and Using Data from a DBMS
13-3: Handling SQL Exceptions - Using SQLException
How It Works
It is not possible to remain connected to the Internet all the time if you are working on
a mobile device and traveling. Nowadays there are devices that allow you to perform
substantial work while you are on the go, even when you are not connected directly to
a database. In such cases, solutions like the CachedRowSet object can come into
play. The CachedRowSet is the same as a regular ResultSet object, except it does
not have to maintain a connection to a database in order to remain usable. You can
query the database, obtain the results, and place them into a CachedRowSet object;
and then work with them while not connected to the database. If changes are made to
the data at any point, those changes can be synchronized with the database at a later
time.
There are a couple of ways to create a CachedRowSet . The solution to this recipe
uses a RowSetFactory (new as of Java SE 7) to instantiate a CachedRowSet .
However, you can also use the CachedRowSet default constructor to create a new in-
stance. Doing so would look like the following line of code:
Search WWH ::




Custom Search