Java Reference
In-Depth Information
rs.updateRow();
Creating an updatable ResultSet is not something that you will need to do every
day. In fact, you might never need to create an updatable ResultSet . However, for
the cases in which such a strategy is needed, this technique can come in very handy.
13-10. Caching Data for Use When Dis-
connected
Problem
You want to work with data from a DBMS when you are in a disconnected state. That
is, you are working on a device that is not connected to the database, and you still want
to have the ability to work with a set of data as though you are connected. For instance,
you are working with data on a portable device, and you are away from the office
without a connection. You want to have the ability to query, insert, update, and delete
data, even though there is no connection. Once a connection becomes available, you
want to have your device synchronize any database changes that have been made while
you were disconnected.
Solution
Use a CachedRowSet object to store the data that you want to work with while off-
line. This will afford your application the ability to work with data as though it were
connected to a database. Once your connection is restored or you connect back to the
database, synchronize the data that has been changed within the CachedRowSet with
the database repository. The following example class demonstrates the use of a
CachedRowSet . In this scenario, the main() method executes the example. Sup-
pose that there were no main() method, though, and that another application on a
portable device were to invoke the methods of this class. Follow the code in the ex-
ample and consider the possibility of working with the results that are stored within the
CachedRowSet while not connected to the database. For instance, suppose that you
began some work in the office while connected to the network and are now outside of
the office, where the network is spotty and you cannot maintain a constant connection
to the database:
Search WWH ::




Custom Search