• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

accessing resultSet

 
shukla raghav
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we access the resultset after the connection is closed
 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

I suggest you try it, and report what happens.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
377
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
shukla raghav
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
shukla raghav
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you sir, you are absolutely correct i will use the CachedRowSet
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic