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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:14:39+00:00 2026-05-20T01:14:39+00:00

I want to know if ResultSet can be closed if I didn’t close it

  • 0

I want to know if ResultSet can be closed if I didn’t close it ? I have a ResultSet is closed exception but I am sure I didn’t close the ResultSet anywhere .
What I do exactly is that I use the ResultSet to perform a SELECT query then I use the same ResultSet because it’s called by this method :

public Object getValueAt( int row, int column )
        throws IllegalStateException {
    // ensure database connection is available
    if ( !dbConnection.isConnectedToDatabase() )
        throw new IllegalStateException( "Not Connected to Database" );

    // obtain a value at specified ResultSet row and column

    try {
        getResultSet().absolute( row + 1 );
        return getResultSet().getObject( column + 1 );
    } // end try
    catch ( SQLException sqlException ) {
        System.out.println("Exception from here dude");
        sqlException.printStackTrace();
    } // end catch

    return ""; // if problems, return empty string object
} // end method getValueAt

So , another question : Is there a way to ensure the ResultSet is opened ?

Third question : Maybe the problem because I never close ResultSets .

What’s the point of closing ResultSet ?

Edit : That’s how statement is being created inside the constructor of a class called DBConnection:

Class.forName(driver);
        // connect to database
        connection = DriverManager.getConnection(url, username, password);

        // create Statement to query database
        statement = connection.createStatement(
     ResultSet.TYPE_SCROLL_INSENSITIVE,
     ResultSet.CONCUR_READ_ONLY );

        //connection ok
        connectedToDatabase=true;

ResultSet is created later whenever I want to execute a statement.

  • 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-20T01:14:39+00:00Added an answer on May 20, 2026 at 1:14 am

    Directly from the docs on ResultSet.close():

    Releases this ResultSet object’s database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.

    …

    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.

    So, if you closed the Statement that generated your ResultSet is closed, you get that exception.

    Another question’s answer: you shouldn’t read results from a ResultSet like that. Perform the select an read all the data you need from the ResultSet at once, close the connection and then later you can read the fetched data as much as you want. You really shouldn’t have an external resource/class calling your getValueAt method, which you expect to still be connected to the database. Connection may be terminated for many other reasons, so that’s not the way to go.

    Third answer: answered above.

    Last answer: releasing resources explicitly, without waiting for it to be closed when Statement is.

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

Sidebar

Related Questions

It seems that the ResultSet will be automatically closed when I close the Connection
I have following code which is running fine, but I want to know if
i want know how i can manage multiple twitter account on iOS in my
I have an android app it displays web view.I want know the app idle
I really didn't want to ask for help as I know I'll eventually figure
I have a django view that I want to return an Excel file. The
I have a problem regarding my JTable, I don't know how can I store
I want to know how I can find interesting relationships between users accounts such
I know that file_get_contents can be used to retrieve the source of a webpage,
I know I can update a single record like this - but then how

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.