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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:18:30+00:00 2026-06-05T04:18:30+00:00

What happens with the statement when result set is closed? Statement stmt = null;

  • 0

What happens with the statement when result set is closed?

    Statement stmt = null;
    ResultSet rs = null;

    try {
        stmt = con.createStatement();
        rs = stmt.executeQuery(query.toString());
        ...
    }

    // lots of code

    rs.close()

Note: A ResultSet object is automatically closed by the Statement
object that generated it when that Statement object is closed,
re-executed, or is used to retrieve the next result from a sequence of
multiple results.

But what happens when ResultSet is closed first?

For what matter, what should happen first?

  • 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-06-05T04:18:31+00:00Added an answer on June 5, 2026 at 4:18 am

    You should close the objects in the reverse order of creating them.
    So first, the ResultSet, then the Statement and in the end, Connection.

    If you don’t close the Statement it stays open and you can execute another query with it (if it’s a PreparedStatement or CallableStatement you are able to change query parameters).

    Also note, that what you quoted is a JDBC specification, and the implementation of it is up to a JDBC driver provider. Usually, you should not trust them, and manually close those objects.

    The other thing – I think more important – if you are using connection pools (like on JBoss), closing connection just releases it back to the pool, and the underlying objects are not released. And because of this, its recommended to always manually release all the objects you created.

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

Sidebar

Related Questions

Connection connection = newConnection.createConnection(); Statement newStat = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet res = newStat.executeQuery(SELECT contactName
I have an issue where I am trying to order a result set by
I am facing an issue while executing queries.I use the same resultSet and statement
I want to print a simple statement print (1=1), i expect the result to
i have the following LINQ statement: var query =(from item in _itemRepository.FindAll() where item.Id
I'd like to run some ALTER TABLE statements on a sqlite3 database. What happens
What happens if we forcefully kill a running thread I have a thread namely
What happens when you serialize data? Seriously, I'm being bothered about what's the use
What happens in the case of a wcf session that has created an asynchronous
This happens when the app loads from Splash screen to Main page. It happens

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.