• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

JDBC?

 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Doder wrote:When you close a connection can you still use the resultset?


No.

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.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic