aspose file tools*
The moose likes Java in General and the fly likes Create a tree from a resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Create a tree from a resultset " Watch "Create a tree from a resultset " New topic
Author

Create a tree from a resultset

Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
Hi,

I need to create a tree structure from a resultset and show them into my JSP. Here is my table sql (grup).



What I really need is a recursive method to search for all the children of each row and build a tree heirarchy. e.g. the data may look like




So looking at the top data my final tree structure should look like


and so on. ORDER_BY show the order in which each element should display in the heirarchy. I am really struggling to find a way on how to have the heirarchy built and really need some help.

Thanks


Here is the SQL i have to het the data



MB<br />Sun Certified Programmer for Java2 Platform
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

I usually use a Map for this. Something like this (pseudo code):
When done roots contains all root nodes. If you have one single tree it should contain only one element.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Create a tree from a resultset