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

  • Home
  • SEARCH
  • 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 6120517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:40:39+00:00 2026-05-23T15:40:39+00:00

I am trying to use some query result to generate another query and execute

  • 0

I am trying to use some query result to generate another query and execute the new query but that does not seem to work. The second query is not being executed. Can someone please tell me why? This is that part of the code.

Statment stmt = connnection.createStatement();
Statment stmt2 = connnection.createStatement();
ResultSet r =  stmt.executeQuery("Select * from employees");
while (r.next()) {
            String Str = "Select name from employees where employeeId = " + (r.getInt(3) + 1);
            System.out.println(str);
            query = stmt2.executeQuery(str);
            System.out.println(query.getString(1));}

The right query seems to be generated, but just won’t execute. Is there a reason why this is so. BTW “query” is declared as resultset.
Thanks

  • 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-23T15:40:39+00:00Added an answer on May 23, 2026 at 3:40 pm

    you can only have one statement executing at one moment in time against one database connection — so you can either open another database connection and execute the second statement in the 2nd connection, or iterate through the resultset from first statement and store the employees database id’s (e.g. in an array/collection) then close that statement and run the second one, this time retrieving the id’s from the array/collection you saved them in.

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

Sidebar

Related Questions

i'm having some trouble trying to use a query result as an array First
I am trying to use JDBC and my query is working in some cases
I'm trying to use some of the new MFC feature pack controls on an
I'm trying to use some of the functions that are in the /lib/libproc-3.2.6.so library
Problem I have a YQL query result that I'm trying to get converted and
I'm trying to run a query that checks if some conditions are true and
I've been quite some time trying to use the Containable Behavior in CakePHP but
I'm trying to use some data from a PlanPlusOnline account. They only provide a
I am trying to use some pinvoke code to call a C function. The
I am trying to use some Word 2007 automation where we give the user

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.