Get disconnected with CachedRowSet

In JDK 1.4, when a you wanted to retrive data from a database into a ResultSet, you should always leave the Connection opend till you mainpluate the data in the ResultSet, if you closed the Connection, data in the ResultSet are gone.
So, in 1.4 the following code is not okay:



Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(url, name, pass);
Statement stmt = c.createStatement();
ResultSet rs = s.executeQuery ( query );
con.close() // Closing connection b4 using rs is not okay
while (rs.next()) {
     //.....
}


Java 5 solution


Java 5 has come with soem new exciting features, among these feature is the new JDBC APIs: CachedRowSet


A CachedRowSet object is a container for rows of data that caches its rows in memory, which makes it possible to operate without always being connected to its data source. Further, it is a JavaBeansTM component and is scrollable, updatable, and serializable. A CachedRowSet object typically contains rows from a result set, but it can also contain rows from any file with a tabular format, such as a spread sheet. The reference implementation supports getting data only from a ResultSet object, but developers can extend the SyncProvider implementations to provide access to other tabular data sources.

An application can modify the data in a CachedRowSet object, and those modifications can then be propagated back to the source of the data.


At this release, as an aid to developers, the RowSet interface has been implemented (as JSR 114) in five of the more common ways a RowSet object can be used. These implementations provide a standard that developers are free to use as is or to extend.

Following are the five standard implementations:


Read More here:
http://java.sun.com/developer/technicalArticles/javaserverpages/cachedrowset/