It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes JDBC? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "JDBC?" Watch "JDBC?" New topic


Sam Doder
Ranch Hand

Joined: Feb 06, 2008
Posts: 204
When you close a connection can you still use the resultset?

For example if I create a jdbc connection then create a PreparedStatment and execute the statement to get a resultset.
If I then close the jdbc connection can I still traverse and get the data of the resultset?

I am just wondering what the difference is in closing a resultset as opposed to closing the entire connection provided you never use more then one resultset per connection.

Is it better to create many jdbc connections and one resultset per connection or to use one jdbc connection and many recordset's?

I have JSP's pages that need to query a database but I am unsure if it is better to create a connection and store it in a Session varable so it is valid to all pages or to create a connection for each page.
Constantly geting a connection and closing a connection.

Also I have jsp functions that must return RecordSets and PreparedStatments but I am unsure if I can have these functions close the connection to the database before returning the RecordSet or PreparedStatment.
I am just worried about leaving unclosed connections dangling behind?

If I have a recordset in a page how can I close the jdbc connection that created the connection just from the knowledge of the recordset?
Because sometime I call a function to get the recordset when I close the recordset I don't want the connection to be open forever never being closed each time I call the function to get a resultset.

Thanks for any help.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63839

Please take the time to choose the correct forum for your posts. This forum is for questions on intermediate Java.

For more information, please read this.

This post has been moved to a more appropriate forum.

Also, please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

A title such as "JDBC" is not helpful. What would happen if all posts on JDBC had such a title?

Please go back and change your post to add a more meaningful subject by clicking the button on your post.

[Asking smart questions] [About Bear] [Books by Bear]
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Sam Doder wrote:When you close a connection can you still use the resultset?


A connection, statement and resultset are to be acquired and closed in the shortest possible scope. If you need to pass the results out of the scope, then you need to map the desired results to a collection of row objects. Read on about the DAO pattern.
rahulash sharma

Joined: Jan 05, 2009
Posts: 15
Answer is No

When you close the connection you can not retrieve the data
one advice don,t ask these type of questions, implement and see result it will improve your basic concepts
I agree. Here's the link:
subject: JDBC?
It's not a secret anymore!