This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes ResultSet after DB closed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet after DB closed" Watch "ResultSet after DB closed" New topic
Author

ResultSet after DB closed

vishvar hariraman
Greenhorn

Joined: Apr 04, 2006
Posts: 20
Hi Everybody

After closing the connection with a database,can we use the ResultSet object to manipulate the data? whether the data is available in ResultSet object or not?
Resultset and statement objects correspond to cursor position in the database,I suppose.We explicitly need to close these objects.So memory leaks are avoided.

If we close DB connection directly without closing statement and resultset objects,still do we have problem of memoryleak? pls friens clarify regarding this


THX
---VISHNUVARDHAN.H




Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Originally posted by vishvar hariraman:

After closing the connection with a database,can we use the ResultSet object to manipulate the data? whether the data is available in ResultSet object or not?




As per Javadoc


Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released.



So once a connection is closed its JDBC resources are released, and you can not use them. If you try to use them you will get an exception.

And It is always a good practice to release the resources explicitly in your program.


Shailesh
[ April 05, 2006: Message edited by: Shailesh Chandra ]

Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
I've never used one, but it sounds like you are talking about a disconnected RowSet.

On the other hand, the most common way to use a ResultSet is iterate through it, creating objects to hold a copy of the data of each row, placing these objects in an appropriate collection, say a List, then closing the ResultSet and working with this data.


There is no emoticon for what I am feeling!
Anantha Reddy.N
Greenhorn

Joined: Mar 21, 2006
Posts: 11
Originally posted by Shailesh Chandra:



So once a connection is closed its JDBC resources are released, and you can not use them. If you try to use them you will get an exception.

And It is always a good practice to release the resources explicitly in your program.


Shailesh

[ April 05, 2006: Message edited by: Shailesh Chandra ]



hi
ResultSet object is Connection Oriented, it is a pointer pointing to result area(rollback/commit segment on DB buffer), it alives as long as Connection object is alive, it will not accessbale after connection is get closed.

yes, u can achive this with disconnected RowSet..refer RowSet API.but it will work jdk1.5 onwords..


Anantha Reddy.N
Anantha Reddy.N
Greenhorn

Joined: Mar 21, 2006
Posts: 11
Originally posted by Shailesh Chandra:



So once a connection is closed its JDBC resources are released, and you can not use them. If you try to use them you will get an exception.

And It is always a good practice to release the resources explicitly in your program.


Shailesh

[ April 05, 2006: Message edited by: Shailesh Chandra ]



hi
ResultSet object is Connection Oriented, it is a pointer pointing to result area(rollback/commit segment on DB buffer), it alives as long as Connection object is alive, it will not accessbale after connection is get closed.

yes, u can achive this with disconnected RowSet..refer RowSet API.but it will work jdk1.5 onwords..

thanks
Ananth
vishvar hariraman
Greenhorn

Joined: Apr 04, 2006
Posts: 20
Thx friens
Vishnuvardhan.H
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet after DB closed
 
Similar Threads
open Resultset and closed connection
Try/Catch/Return
Closing of connection object in Stateless Session Beans
whats the use of closing ResultSet ?
Is connection.close(); enough?