A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Databases
»
JDBC
Author
ResultSet Thru ResultSet
Sanjay Deshpande
Ranch Hand
Joined: May 22, 2001
Posts: 111
posted
May 17, 2002 00:36:00
0
I have a result set rs.
Depending on some value from rs i wanna get another resultset rs2with diff query.
How to do this?
I ve code like this
Connection con1=DriverManager.getConnection(URL); Statement stmt1 = con1.createStatement(); String qry="SELECT PONumber FROM Order"; ResultSet rs= stmt1.executeQuery(qry); try { while (rs.next()) { Statement stmt2 = con1.createStatement(); String qry2="SELECT BuyerName FROM Order where PONumber='"+rs.getString("PONumber")+"'"; ResultSet rs2= stmt2.executeQuery(qry2); rs2.next(); { out.println(rs2.getString("BuyerName")); } rs2.close(); stmt2.close(); } rs.close(); con1.close(); } catch()
IS IT OK?
[ Edited by Dave to format code ]
[ May 19, 2002: Message edited by: David O'Meara ]
Jamie Robertson
Ranch Hand
Joined: Jul 09, 2001
Posts: 1879
I like...
posted
May 17, 2002 07:02:00
0
you might want to change
rs2.next(); { out.println(rs2.getString("BuyerName")); }
to this
if ( rs2.next() ) { out.println(rs2.getString("BuyerName")); } else { //process for no records found }
Also, if you expect many rs1's, then it might be worth your while to use a prepared statement in the while loop.
Jamie
Mahesh Mamani
Ranch Hand
Joined: Jun 25, 2001
Posts: 110
posted
May 20, 2002 03:04:00
0
U may also consider putting creating and closing the Statement calls for the second rs outside the loop. U may check time-difference among the two processes and decide.
MSM
I agree. Here's the link:
http://aspose.com/file-tools
subject: ResultSet Thru ResultSet
Similar Threads
two dropdown menus
junk characters for byte charset
nested resultsets
I M NOT ABLE TO DEFINE VARIABLES IN JSP.
stored procedures in a loop... what gives?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter