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

  • SEARCH
  • Home
  • 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 6560643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:29:13+00:00 2026-05-25T13:29:13+00:00

I am unsure whether a statement and resultset should be closed after each query

  • 0

I am unsure whether a statement and resultset should be closed after each query or after all my queries have been made (ie at the same time i close the connection)?

Correct me if I’m wrong, but I’m pretty sure both work?

However, would the database eventually crash if I didn’t close a statement after each query and then performed a lot of queries?

On the other hand, would it be inefficient and time-wasting to keep closing & creating statements for every query?

I’ve read up a lot on this problem before asking this question, but I’m still uncertain. Any help appreciated,

tre.

  • 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-25T13:29:14+00:00Added an answer on May 25, 2026 at 1:29 pm

    From http://www.precisejava.com/javaperf/j2ee/JDBC.htm#JDBC118:

    Close ResultSet when finished

    Close ResultSet object as soon as you finish working with ResultSet
    object even though Statement object closes the ResultSet object
    implicitly when it closes, closing ResultSet explicitly gives chance
    to garbage collector to recollect memory as early as possible because
    ResultSet object may occupy lot of memory depending on query.

    In a nutshell, you don’t have to explicitly close your ResultSet objects, but it’s better to do so to free up memory earlier on. Failing to close your ResultSet objects will just cause the memory that it occupies (which can be small, or large, depending on the size of the result set) to be occupied until the corresponding Statement object is closed.

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

Sidebar

Related Questions

I'm writing some Erlang code and I'm very unsure whether I should let everything
I am unsure whether I should: Make one view where I use view-parameters Or
I'm creating a multi-threaded application in C using Linux. I'm unsure whether I should
I am using NHibernate with mySQL 5 and I am a bit unsure whether
jQuery has the .ready() function, but I am unsure whether this is what I
I'm having trouble doing simple functions on a data frame and am unsure whether
I was unsure whether to ask here or in superuser, but this site seemed
I have a Java class that I'm debating what I should make it into
I have a class below, i have extracted all the properties to a Interface
I have a data structure which represents a train, which can be made up

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.