Create two statements and two resultsets.
Mark Weidner <[EMAIL PROTECTED]>@JAVA.SUN.COM> on 12/26/2000 11:52:42 AM
Please respond to "A mailing list for discussion about Sun Microsystem's Java
Servlet API Technology." <[EMAIL PROTECTED]>
Sent by: "A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology." <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
cc:
Subject: Multiple/Nested Resultsets
Hi Everyone,
I'm looking to use nested resultsets to retrieve data. Basically, I
need to retrieve data based on certain values retrieved by another
resultset. The following code is a much simplified version of what I'd like
to do. The real SQL statements are much more complex, and it would be a
huge performance hit to attempt to retrieve all the data in one ResultSet.
It is my understanding that executing a query on an existing statement
deletes the references to any previous resultset. Therefore, copying the
data from a first resultset to an object would work (Vector/Hashtable?), but
there would be serious performance implications there as well. Any ideas?
(I apologize....I come from the ASP world)
Thanks.
-Mark
---------------
//Connection con has already been created
Statement stmt = con.createStatement();
ResultSet rsQuestions = stmt.executeQuery("SELECT questionID FROM
Questions");
//Loop through questions from first resultset
while (rsQuestions.next()) {
int ID = rsQuestions.getInt("questionID");
//Lookup results from second resultset which uses paramaters from
the first resultset
ResultSet rsText = stmt.executeQuery("SELECT questionText FROM Text
WHERE questionID=" + ID);
String sText = rsText.getString("questionText");
out.println("Question ID: " + ID + " Question Text: " + sText)
}
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html