Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ResultSet within Resultset

Posted on 2001-07-05
16
Medium Priority
?
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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
 

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 75 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

704 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