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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:21:06+00:00 2026-06-16T03:21:06+00:00

Forgive my lack of creativity when it comes to titeling this problem correctly. Hi,

  • 0

Forgive my lack of creativity when it comes to titeling this problem correctly.

Hi, i’ve spent the last 3 hours trying to figure out this problem, and I think i’ve figured it out, but the solution to it still eludes me. I have this very simple code.

    Statement stmt = db.getStatement();
    ResultSet queryResult = stmt.executeQuery("SELECT * FROM users");

    while(queryResult.next()) {
        username = queryResult.getString("username");
        password = queryResult.getString("password");
        privilege = queryResult.getInt("privilege");

        queryResult = stmt.executeQuery("SELECT * FROM division");
        while(queryResult.next()) {}

        users.add(new User(username, password, privilege));
    }

Now, this piece of code is dumbed down to illustrate what the problem is in my code. I don’t have a while loop which contains nothing, obviously.

I’ve come to realize that whenever I want to fetch something from the database, I can only do it with the resultset within one loop. If I write a “nested-resultset-loop”, I either get “Operation… ResultSet closed”, “Cannot find column ‘username'”, or some other error.

I have alot of these nested resultset loops throughout my DAO code, to fetch everything from the database. Since i’m not that strong at MySQL, this was the simple solution (I have VERY little time left to do this program)… Since I used to do similiar back in PHP.

I’m not saying this code is good design, but for the sake of time, I really do not care much at the moment about good class design. So any solution you have in mind, regardless of poor design choice is welcomed.

Another solution would be to split everything up in single loops, because that tends to work (very simple). But that means modifying alot of the code, and i’d prefer this to be the backup plan.

  • 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-16T03:21:07+00:00Added an answer on June 16, 2026 at 3:21 am

    You can’t interleave the resultsets like that, see the API documentation:

    By default, only one ResultSet object per Statement object can be open
    at the same time. Therefore, if the reading of one ResultSet object is
    interleaved with the reading of another, each must have been generated
    by different Statement objects. All execution methods in the Statement
    interface implicitly close a statment’s current ResultSet object if an
    open one exists.

    I think you’ll be ok if you create separate statements for the different queries. The usual practice that I’ve seen is to have a separate DAO method for each query, in order to keep the DAO methods as simple and as reusable as possible. (That implies that the DAO isn’t in charge of transaction demarcation, but that a higher level component, like a service, controls what’s in a transaction.)

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

Sidebar

Related Questions

I'm trying to learn C++ so forgive me if this question demonstrates a lack
Forgive me for this unbeautiful code, but I'm trying to get it to work
First please forgive me for total lack of understanding of Varnish. This is my
probably this is a lack of attention issue, if so, forgive me, but I
Forgive me for asking what some might think are stupid questions. I am trying
Forgive me if this is a silly question....but I think back to my Comp.
Forgive me as this is probably an easy question for your jQuery guys out
Please look at this code (and forgive the lack of knowledge). It outputs errors
i'm not sure what terms python uses for objects - forgive my lack of
Forgive me for the upcoming question, lol. (Im terribly new at this) I have

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.