Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Is recursion needed? if so, then how?

807603Jan 21 2008 — edited Jan 21 2008
Hi, hope anybody can help me with this problem I'm having.

I've created a java bean called Category which looks something list this
public class Category
{
  private int id;
  private String name;
  private Vector children; // a vector of Category objects

  public Category(){};

  public void setId(int id)
  {
    this.id = id;
  }

  public int getId()
  {
    return id;
  }

  // rest of get and set methods
}
I've store the data inside a database table like the below
category id                      name                          description                           parent id
1                                category 1                   This is a base folder                  -1
2                                category 2                   This is also a base folder           -1
3                                sub category 1             This is a sub folder                    2
4                                sub category 2             ...                                            2
5                                sub sub category          ....                                           4 
I need to load this data back out of the database into a category array (Category[] cat) so I loop through the array and display all category (and child categorys) on a page.

Will I need recursive methods to retreive the data and display it on the screen? I'm trying to write one but I keep getting into an infinite loop!!!!

Can anybody help me out?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 18 2008
Added on Jan 21 2008
5 comments
124 views