Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JDBC and Relational Databases
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
JDBC and Relational Databases
ResultSet Thru ResultSet
Sanjay Deshpande
Ranch Hand
Posts: 111
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 1879
I like...
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 110
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
I M NOT ABLE TO DEFINE VARIABLES IN JSP.
junk characters for byte charset
two dropdown menus
stored procedures in a loop... what gives?
nested resultsets
More...