aspose file tools*
The moose likes JDBC and the fly likes accessing resultSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "accessing resultSet" Watch "accessing resultSet" New topic
Author

accessing resultSet

shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
Can we access the resultset after the connection is closed
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38340
    
  23
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

Joined: May 14, 2008
Posts: 5823
    
    7

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.


JBoss In Action
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30293
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
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

Joined: Apr 14, 2004
Posts: 10336


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?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
shukla raghav
Ranch Hand

Joined: Aug 03, 2008
Posts: 200
Thank you sir, you are absolutely correct i will use the CachedRowSet
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: accessing resultSet