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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:35:05+00:00 2026-06-17T05:35:05+00:00

Im new in java and SQL, Im repeating a problem that i don’t know

  • 0

Im new in java and SQL, Im repeating a problem that i don’t know how to avoid it:

assume i want to make two executeQuery, one inside the other in the getRequestsFromDB method i make the first executeQuery and in the second method isProfessionalHasThatProfession i make the second executeQuery:

 private Vector<ClientRequest> getRequestsFromDB() throws SQLException {
    Vector<ClientRequest> retVal = new Vector<ClientRequest>();
    ResultSet result = null;
    try {
        for (int i=0 ; i<_userBean.getProfession().length ; ++i ){
            result = _statement.executeQuery("SELECT * FROM "+_dbName+"."+CLIENTS_REQUEST_TABLE+" WHERE "+CLIENTS_REQUEST_T_PROFESSION+"='"+_userBean.getProfession()[i]+"'");               
            while(result.next()){ //HERE IN THE SECOND LOOP GETTING NULL EXCEPTION

                if(isProfessionalHasThatProfession(result.getString(CLIENTS_REQUEST_T_PROFESSION))){
                    retVal.add(cr);
                    ClientRequest cr = new ClientRequest
                            (result.getString(CLIENTS_REQUEST_T_CLIENT_ID), 
                            result.getString(CLIENTS_REQUEST_T_CITY),
                            result.getString(CLIENTS_REQUEST_T_DATE),
                            result.getString(CLIENTS_REQUEST_T_PROFESSION));
                }
            }
        }
    } catch (SQLException ex) {
        throw ex;
    }
    return retVal;
}

the second function:

private boolean isProfessionalHasThatProfession(String profession) throws SQLException {             
    ResultSet result = null;
    try {
        result = _statement.executeQuery("SELECT "+WORKER_PROFESSIONS_T_PROFESSION+" FROM "+_dbName+"."+WORKER_PROFESSIONS_TABLE+" WHERE "+WORKER_PROFESSIONS_T_PROFESSIONAL_ID+"='"+_userBean.getProId()+"'");
        while(result.next()){
            if(result.getString(1).equals(profession)){
                return true;
            }
        }
    } catch (SQLException ex) {
        throw ex;
    }
    return false;
}

in the second loop im getting a SQLException: “operation not allowed after ResultSet closed”, i have tried:
close in finally the result with result.close() but also i get exception null pointer exception.

i’m really don’t know how to deal with that, ideas?
Thank You!

  • 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-17T05:35:06+00:00Added an answer on June 17, 2026 at 5:35 am

    youre reusing _statement (which i assume is global?) to get 2 different ResultSets, but then you return to the 1st ResultSet (in the outside function) after you got the 2nd (inside the inner function, which automatically closed the 1st) – try using 2 separate statements

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

Sidebar

Related Questions

I really don't know what's going on. I'm new to Java, fairly new to
java.util.Date date = new java.util.Date(); java.sql.Date today = new java.sql.Date(date.getTime()); //2012-03-23 java.sql.Time time =
I am starting a new Java web project that will be worked on by
I am new to java and database connections and I am trying to make
Disclaimer: I'm completely new to Java EE/EJB and all that, so bear with me.
How come that java.sql.PreparedStatement#setDate on dateTime mysql column always results in Date format like
I'm new to BIRT. I know it has a java based reporting engine. Can
I know that NoSQL databases are very new. I am also new in this
public java.sql.Date getDate() { java.sql.Date date = new java.sql.Date(2001, 10, 10); return date; }
I'm pretty new to Java, and I'm writing a program that needs to store:

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.