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 7619875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:47:59+00:00 2026-05-31T03:47:59+00:00

while it has been discussed many times, to close the database resources in shortest

  • 0

while it has been discussed many times, to close the database resources in shortest scope possible. I would like to know if its okay to reuse the statement objects, which does not return any result set.
forexample a code like this,

 Statement st = con.getStatement();
 st.execute(TABLE1_DELETE_Query);
 st.execute(TABLE2_DELETE_Query);
 st.close();

I looked at similar questions on SF, yet I was unable to find that could have answered mine. If it has been answered, kindly just mention the reference.

Thanks

  • 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-31T03:48:01+00:00Added an answer on May 31, 2026 at 3:48 am

    The lifetime of Statements should be kept short term, but re-using them is perfectly fine.

    A single unclosed ResultSet can cause an application to hang, but you can have 100s of unclosed statements without a problem. Typically a statement will be holding on to a very small piece of memory associated with the database connection and little else, but it can hold multiple result sets as could be returned by the getMoreResults() method, warnings for the getWarnings() method.

    Reusing a Statement many times within a single method and then closing it is good practice as it saves needlessly creating extra Statements. Creating a Statement and hanging on to it just in case it is wanted is bad practice.

    PreparedStatements are intended to be re-used, but it is still best to keep them within the scope of a single method, as that guarantees they have a short term life-span.

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

Sidebar

Related Questions

Though this topic has been discussed many times in this forum and all other
I know this has been discussed earlier but I couldn't find a satisfactory answer.
So I'm embarking on an ASP.NET MVC project and while the experience has been
It has been quite a while since I am getting this error in the
This has been annoying me for a while in several XCode projects. I really
Ruby has been around for a while now so I was wondering if there
This has been annoying me for a while yet the solution must be really
This one has been bugging me for a while now. Is there a way
This one has been stumping me for a while. But I'm no expert. This
Something that has been troubling me for a while: The current wisdom is that

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.