Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Best way to store nodes in the database so that its will be easy to create Tree.

  1. #1
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Best way to store nodes in the database so that its will be easy to create Tree.

    Dear Friends,


    Fields Created in the table are

    Key | Name | Parent
    --------------------------------------
    101 | Computer |
    102 | Software | 101
    103 | Harware | 101
    104 | Java | 102
    105 | Ram | 103



    Tree will look like

    Computer
    |
    |_____Software
    | |
    | |______java
    |
    |_____Hardware
    |
    |______Ram


    I m feeding the table in this format , Its very tedious to develop tree from the structure like this.


    Second way i m thinking is


    Key | Name | Parent
    --------------------------------------
    101 | Computer |
    102 | Software | 101
    103 | Harware | 101
    104 | Java | 101\102
    105 | Ram | 101\103


    Please suggest me some way so that it would be easy to create tree.

    and if possible please provide some demo code.
    Thanks and Regards
    Dan Brown

    Common Java Mistakes


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Best way to store nodes in the database so that its will be easy to create Tree.

    Storing trees in SQL is not easy. See the following for two methods of storing tree data. Each has its advantages and the above example represents the first method.
    Managing Hierarchical Data in MySQL

  3. #3
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: Best way to store nodes in the database so that its will be easy to create Tree.

    Thank you very much
    Its really worthy.

    Thanks for the quicker resonse.
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

Similar Threads

  1. To Create and Admin an database
    By JavaNoob89 in forum Object Oriented Programming
    Replies: 2
    Last Post: December 10th, 2010, 10:15 AM
  2. How to create a database in my cell phone?
    By Viggopiano in forum Java ME (Mobile Edition)
    Replies: 2
    Last Post: July 12th, 2010, 07:26 AM
  3. Create a tree from list of strings
    By ayri in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 11th, 2010, 04:32 AM
  4. Replies: 0
    Last Post: April 15th, 2010, 05:13 AM
  5. How can i store ArrayList objects in Access database
    By frankycool in forum JDBC & Databases
    Replies: 0
    Last Post: November 4th, 2009, 12:44 AM