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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:29:42+00:00 2026-05-19T10:29:42+00:00

Rather than having complex SQL queries, tries, catch and finals everywhere in the code

  • 0

Rather than having complex SQL queries, tries, catch and finals everywhere in the code I have a method execute(SQL, up to three inputs) however if trying to access the ResultsSet this produces outside of the execute you get the error:

"Operation not allowed after ResultSet closed"

Which is because when you close the PreparedStatement it closes the ResultsSetToo (and there seems to be no way around it).

Is there a way to fix this? The only thing I could think of was converting it to an array which is stored

Many thanks for your time,

  • 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-19T10:29:42+00:00Added an answer on May 19, 2026 at 10:29 am

    I have encountered the same problem in the past. Now i use this method:

    public ArrayList<Map<String, String>> getListOfMapsFromSQL(String sql) throws SQLException {
        con = DriverManager.getConnection(url,user,pass);
        stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
        ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
    
        rs = stmt.executeQuery(sql);
        ResultSetMetaData rsmd = rs.getMetaData();
    
        while(rs.next()){
            Map<String, String> fieldsMap = new HashMap<String, String>();
            for(int i=1; i<=rsmd.getColumnCount(); i++){
                fieldsMap.put(rsmd.getColumnLabel(i), rs.getObject(i).toString());
            }
            list.add(fieldsMap);
        }
    
        list.trimToSize();
        stmt.close();
        con.close();
        return list;
    }
    

    Instead of returning a ResultSet, it returns a list of Maps(each one representing 1 row). The first String is the column Label, and the second is the column’s value. I hope it helps. 🙂

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

Sidebar

Related Questions

Rather than having three separate controllers and their associated *.xib files I am trying
I have created some ms build tasks for my VS project. Rather than having
I have been sold on mod_wsgi and apache rather than mod_python. I have all
Is there any way to email status updates to twitter, rather than having to
Rather than population said DOM object with an external page such as HTML CFM
Rather than scraping a Ruby version of this algorithm off the net I wanted
Has anyone used Lucene.NET rather than using the full text search that comes with
I'm developing an operating system and rather than programming the kernel, I'm designing the
(This is a question about the UI rather than the technology required to do
Does creating an object using reflection rather than calling the class constructor result in

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.