Solved

ResultSet within Resultset

Posted on 2001-07-05
16
310 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
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!

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

756 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