Solved

ResultSet within Resultset

Posted on 2001-07-05
16
309 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
reverse digits of a number using for loop 5 52
java jdbc batch example 8 40
null output 3 35
restrict decimal places for double datatype 10 19
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

808 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