1. The easy way if you are using an oracle database, this gets them all in one
query
select name
from table
start with id = ?
connect by parent = prior id
2. use a stack
Brief example...
class Person {
int id;
String name;
Person(int id, String name) {
this.id = id;
this.name = name;
}
}
// Create node to start with
Person root = new Person(4, "Jackie");
Stack stack = new Stack();
// Place starting node on stack
stack.push(root);
Connection con = ... get connection here
PreparedStatement ps = con.prepareStatement("select id, name from table =
where parent = ?");
do {
Person current = (Person) stack.pop();
// Print current item on stack
out.println("<b>" + current.name + "</b><br>");
// Set parent to look for
ps.setInt(1, person.id);
// Get children
ResultSet rs = ps.executeQuery();
while (rs.next()) {
// Place children on stack
stack.push(new Person(rs.getInt(1), rs.getString(2)));
}
rs.close();
} while(!stack.isEmpty()); // Continue as long as there are more children
ps.close();
con.close();
-----Original Message-----
From: Frank Mancini [EMAIL PROTECTED]
Sent: Mon, 12 Nov 2001 14:04:14 -0800
To: [EMAIL PROTECTED]
Subject: Please help! Recursive loop in JSP
I have a recursive looping problem here.
For example, say I have this table
id, name, parent
1,john,4
2,bill,3
3,cathy,4
4,jackie,0
5,jeff,4
6,joe,7
7,amy,0
Essentially,
jackie doesn't have a parent, but has john, jeff and cathy as children. bill
is the child of cathy and thus jackies grandchild.
How would I do this query such that I say I want to see all the children
(including everyone below him/her) below, say jackie...this is really a self
join to oneself with an unknown number of levels below.
How would I do this in jsp do display all of jackies relatives below her?
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com
___________________________________________________________________________
Visit http://www.visto.com.
Find out how companies are linking mobile users to the
enterprise with Visto.
==========================================================================To
unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com