File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Doubt in JDBC" Watch "Doubt in JDBC" New topic

Doubt in JDBC

Shivakumar Mallikarjun

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

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: 1082

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 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.


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

Joined: Jan 10, 2002
Posts: 63870

"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.

Forum Bartender

[Asking smart questions] [About Bear] [Books by Bear]
Shivakumar Mallikarjun

Joined: Jul 08, 2005
Posts: 4
Thanks Paul & Shailesh for your valuable replies.
I agree. Here's the link:
subject: Doubt in JDBC
It's not a secret anymore!