File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Doubt in JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Doubt in JDBC" Watch "Doubt in JDBC" New topic
Author

Doubt in JDBC

Shivakumar Mallikarjun
Greenhorn

Joined: Jul 08, 2005
Posts: 4
Presume that I have created a connection to DB, created Statement & execute the statement, result what I will get is ResultSet.
Immediately after this part, if I close the connection will I be able to retrieve the data from ResultSet?
[ September 16, 2005: Message edited by: Bear Bibeault ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

No. If you close a connection you discard the ResultSet. You will need to use a CachedRowSet or copy the data from the ResultSet into another Collection if you want to keep it in memory.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

In the continuation of paul's answer, every execution of query create a cursor, and this cursor can be either server side of client side depending on driver's implementation.

Your resultset does not hold any record once query is executed it points to the cursor created and moves to next or previous row on calling resultset.next() or resultset .previous() once you close the connection resultset will loose link to cursor and you will not be able to fetch data from resultset.

Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

"Shivakumar M J Shivakumar M J",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious. Weird permutations like repeating your name twice are not allowed.

Thanks!
bear
Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Shivakumar Mallikarjun
Greenhorn

Joined: Jul 08, 2005
Posts: 4
Thanks Paul & Shailesh for your valuable replies.
 
wood burning stoves
 
subject: Doubt in JDBC
 
Similar Threads
consuquences of not closing ResultSet?
Doubt in closing connection, resultset, statemnet object???
Does ResultSet close when connection closes?
Regarding java.sql.Connection
BMP