I am using a javax.sql.rowset.CachedRowSet
object which I pass around in my code. The ResultSet
from which it was populated is closed just before the CachedRowSet
is passed to the rest of my code (only for reading, I do not update or modify it in any way):
public CachedRowSet getData(String query) throws SQLException {
RowSetFactory aFactory = RowSetProvider.newFactory();
CachedRowSet crs = aFactory.createCachedRowSet();
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(query);
crs.populate(rs);
} finally {
DbUtils.closeQuietly(null, stmt, rs);
}
return crs;
}
Given the above setup, does it make sense to also close()
or release()
the CachedRowSet
object when I am done with it? This answer seems to suggest that close()
doesn't hurt but doesn't address release()
, or the difference between the two. I suppose I could do a release()
followed by a close()
just in case but I would like to understand a bit more. Note that I even serialize the CachedRowSet
object and then internalize it from a String
in an other module so I could also call close()
and release()
on the re-internalized instance which doesn't make any sense.