Solved

ResultSet within Resultset

Posted on 2001-07-05
16
306 Views
Last Modified: 2006-11-17
I have mutiple results from the 1st query. I have to base on one of another fields from the 1st query to get the result set from the 2nd query. When I try to do it this way, only 1 resultset is return.

Can we do a resultset within a resultset?

String sql_GetPlanBundle = "SELECT PLAN_BUNDLE_ID, PROD_CODE, PLAN_CODE, PLAN_STATUS, PLAN_NETWORK_CODE FROM PLAN_BUNDLE WHERE PLAN_BUNDLE_ID IN (SELECT PLAN_BUNDLE_ID FROM CORP_PLAN WHERE BRN ='"+BRN_No+"')";
                   rs_GetPlanBundle = stmt.executeQuery(sql_GetPlanBundle);
                         
                         flag =0;
                   while (rs_GetPlanBundle.next())
                         {
                              out.println("");
                              out.println("<tr><td>" + rs_GetPlanBundle.getString("PLAN_CODE") + "</td>");
                              out.println("<td>" + rs_GetPlanBundle.getString("PLAN_NETWORK_CODE") +"</td>");
                              out.println("<td>" + rs_GetPlanBundle.getString("PROD_CODE") + "</td>");
                              out.println("<td>" + rs_GetPlanBundle.getString("PLAN_STATUS"));                        
                                   out.println("</td>");
                              String BUNDLE_ID = rs_GetPlanBundle.getString("PLAN_BUNDLE_ID");
                              out.println("<td>" + BUNDLE_ID + "</td>");
                             
                              out.println("<td>");
                              String sql_GetPlanBundleVAS = "SELECT DESCRIPTION FROM VAS WHERE PROD_CODE IN (SELECT PROD_CODE FROM PLAN_BUNDLE_VAS WHERE PLAN_BUNDLE_ID ='"+BUNDLE_ID+"')";
                              rs_GetPlanBundleVAS = stmt.executeQuery(sql_GetPlanBundleVAS);
                              while(rs_GetPlanBundleVAS.next())
                                        out.println(rs_GetPlanBundleVAS.getString("DESCRIPTION") + ",");
                              rs_GetPlanBundle.close();    
                              out.println("</td></tr>");
                              flag =1;
                         }
0
Comment
Question by:rac13
  • 6
  • 5
  • 5
16 Comments
 
LVL 3

Expert Comment

by:ibo
ID: 6258618
u close the wrong resultset dude:

String sql_GetPlanBundleVAS = "SELECT DESCRIPTION FROM VAS WHERE PROD_CODE IN (SELECT PROD_CODE FROM PLAN_BUNDLE_VAS WHERE PLAN_BUNDLE_ID ='"+BUNDLE_ID+"')";

rs_GetPlanBundleVAS = stmt.executeQuery(sql_GetPlanBundleVAS);
                             
while(rs_GetPlanBundleVAS.next())
out.println(rs_GetPlanBundleVAS.getString("DESCRIPTION") + ",");

rs_GetPlanBundle.close();     <<-------

this one should be rs_GetPlanBundleVAS.close() right?
0
 
LVL 3

Expert Comment

by:ibo
ID: 6258625
therefore, immediately after the first iteration, the loop stops.. printing only one record.
0
 
LVL 3

Expert Comment

by:ibo
ID: 6258632
dont forget to close the rs_GetPlanBundle resultset outside the where.. loop
0
 

Author Comment

by:rac13
ID: 6258652
I have changed the closing of the correct recordset, but there is still only 1 data been display.
0
 
LVL 3

Expert Comment

by:ibo
ID: 6258668
which resultset? the descriptions? how many records are u expecting?
its probably ur sql statement.
0
 
LVL 3

Expert Comment

by:ibo
ID: 6258670
which resultset? the descriptions? how many records are u expecting?
its probably ur sql statement.
0
 

Author Comment

by:rac13
ID: 6258679
I expect 3 recordset from the 1st query:
eg:
Plan Bundle ID | Plan Bundle VAS
114523653B        Free A, Free B
111111225A        Free C, Free H

Plan bundle is from the 1st query, but the VAS is from the 2nd query
0
 
LVL 92

Expert Comment

by:objects
ID: 6258714
I have a recollection of having a similiar problem in the past. I think it ended up being that only one ResultSet could exist at one time, so I had to read all the data from the first query, storing what I needed. Then once all rows were read then do the second query using the stored values.

I'll see if I can confirm this and get back to u.
 
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:rac13
ID: 6258720
I expect 3 recordset from the 1st query:
eg:
Plan Bundle ID | Plan Bundle VAS
114523653B        Free A, Free B
111111225A        Free C, Free H

Plan bundle is from the 1st query, but the VAS is from the 2nd query
0
 
LVL 92

Expert Comment

by:objects
ID: 6258735
Try using a seperate Statement for each query, I think you can only have a single open ResultSet per Statement.
0
 
LVL 92

Expert Comment

by:objects
ID: 6258748
I depends on your JDBC driver and whether it supports multiple open Stements and/or ResultSets, but try using a seperate statement object per query and if this doesn't work the you'll have to read all the first query, close it and then run your second one.

Or possibly see if you can do what you need using a database join, or a stored procedure.
0
 

Author Comment

by:rac13
ID: 6258774
How can we check if it allows mutiple open statement?
0
 
LVL 92

Accepted Solution

by:
objects earned 25 total points
ID: 6258789
Try it and see if it works :)
0
 

Author Comment

by:rac13
ID: 6258814
Yes.. after I created 2 statment, I can get it out to what I want. Thanks a lot.
0
 
LVL 92

Expert Comment

by:objects
ID: 6258829
Only a B :-)
Thanks for the points.
0
 

Author Comment

by:rac13
ID: 6258841
Grade low ponits high... :)
hee.. hee....
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scoreUp challenge 14 48
How Complex Is This Java Course ? 9 63
Running Jira on Raspberry PI 2? 3 130
recursion example 16 69
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now