This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Can we access the resultset after the connection is closed
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
4
posted
0
Have you looked in any documentation, or the Java™ Tutorials? I looked in the Java tutorial link, and it didn't say anything about closing connections, so maybe you can still gain access to the ResultSet after closing the Connection.
It all depends on the driver implementation. In many cases the ResultSet is merely a proxy that grabs blocks of data from the database (in other words, it does not store the full response to the query). If your request for the next row in the ResultSet requires a trip to the database, that will fail if the connection is closed. Also, there is an implicit link between the Result Set, the Statement it came from, and the Connection used to create the Statement. If you close the Connection, the Statement and ResultSet might also be closed by the driver. But as I said, a lot of this is dependent on how the driver is implemented.
It also depends on the type of ResultSet. If you search for "disconnected resultset" or "CachedRowSet" you can see a way to cache the whole result set in memory. The downside is that the whole result set is in memory - which may be more expensive than using a connection.
Thankx to all of you, here is another question in my mind now. as suggested by Peter Johnson and Jeanne Boyarsky that it depends on driver implementation and there is also a possiblity that a driver implmentation may allow resultset to be accessible after closing of the connection, if the ResultSet is implemented in a manner that it take a snapshot of the database once and we use this snapshot. i wished to know the following
1. Will such an implementation be faster than the other ?
2. can you name any such drivers that implement the ResultSet in such a manner which does not require a constant connection with the database to access the ResultSet?
1. Will such an implementation be faster than the other ?
It depends.
2. can you name any such drivers that implement the ResultSet in such a manner which does not require a constant connection with the database to access the ResultSet?
This detail is not something the API can guarentee so why use it? If you don't write to the interface you are beholden to minor changes in the implementation, and you are restricted to specific databases. Why do you need to use a ResultSet that behaves like a CachedRowSet? Could you not just use a CachedRowSet?