Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create a tree from a resultset

 
Mike Boota
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic