Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6351533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:01:37+00:00 2026-05-24T22:01:37+00:00

Looking back over my code I find that I occasionaly have written: ResultSet rs

  • 0

Looking back over my code I find that I occasionaly have written:

ResultSet rs = conn.createStatement().executeQuery("select * from main");
//snip
rs.close();

and sometimes I’ve written

Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("Select * from main");
//snip
rs.close();
st.close();

In the second code segment, it’s more obvious that the Statement is closed, but is it also closed in the first one? conn.createStatement() returns a statement object, but when it’s instantiated like that I don’t see any easy way to close it after I’m done. Should I just rewrite the various bits of code to use method #2?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:01:39+00:00Added an answer on May 24, 2026 at 10:01 pm

    The Statement will be automatically closed when it is garbage collected, but you need to explicitly close it if you want to free the resources as soon as you’re done with them.

    Note, however, that the reverse actually does work. That is, closing a Statement also closes the ResultSet associated with it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From looking over the documentation, it seems that the form clean() method is only
I have been looking all over google to find some answers to my questions
I have some Visual C++ code that receives a pointer to a buffer with
So I have been looking all over and I haven't quite found what I
I am a bit rusty on my Haskell and am looking to ramp back
I asked this question a while back but now I'm looking to implement an
I'm looking for ideas and opinions here, not a real answer, I guess... Back
PHP5.2.x back end. The text data transfer is using JSON objects. Am looking at
I'm setting up a web application with a FreeBSD PostgreSQL back-end. I'm looking for
Looking for feedback on : http://code.google.com/p/google-perftools/wiki/GooglePerformanceTools

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.