Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6609085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:40:42+00:00 2026-05-25T19:40:42+00:00

Planning on building a Folder based structure in Java. I will be using a

  • 0

Planning on building a Folder based structure in Java.

I will be using a jquery plugin for the GUI, so I don’t need need information on how to display the folder structure.

I am looking for the backend logic on how folder information is stored, such that it can be retrieved in a quick and efficient manner.

Each folder will have multiple subfolders.
From a leaf folder, we should be able access the root quickly and efficiently

Example:

+Folder1
  |__SubFolder1_1
  |__SubFolder1_2
        |_SubSubFolder1_2_1
        |_
+Folder2
  |__SubFolder2_1
        |_SubFolder2_1_1
        |_SubFolder2_1_2
             |_SubFolder2_1_2_1

New folders could be added randomly.
Folder can be renamed.
Folders can be deleted.

My Question is:

How would these folder details be stored in the database?

Again, I am looking for a fast and efficient means of storing and retrieving this information.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:40:43+00:00Added an answer on May 25, 2026 at 7:40 pm

    For storing in DB, the easiest and most straight forward way is to have an parent_folder_id for each folder/node. This should be good enough in most scenario, especially you are going to construct the folder object structure and do manipulation base on the object model.

    Depends on your requirement, there is a quite common case that you need to

    1. Find out all subfolders under certain folder
    2. Perform the lookup directly from DB, by SQL.

    If it is what you are looking for, then there is a interesting method that you may have a look:
    Each DB record will have 2 extra number field, let’s call it LEFT and RIGHT

    assume a tree like this:

    ROOT
      + A
      | + A1
      | + A2
      + B
        + B1
    

    What is going to be stored in DB is

    Node  LEFT  RIGHT  ... other fields
    ROOT   1    12
    A      2    7
    A1     3    4
    A2     5    6
    B      8    11
    B1     9    10
    
    • each parent node is having LEFT = first child’s LEFT – 1, and RIGHT = last child’s RIGHT + 1
    • leaf node will have LEFT and RIGHT being 2 consecutive number
    • each node’s LEFT should be = prior sibling’s RIGHT + 1, RIGHT = next sibling’s LEFT – 1

    When you need to find all nodes under certain node (N) by SQL, simply find out all nodes with LEFT > N.LEFT and RIGHT < N.RIGHT

    You can easily perform insert/delete by bulk updating related nodes by (not a difficult task, leave it to you 😛 )

    This is probably not very OO friendly but in case the requirement I mentioned is what you need, u may consider using this method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building an application and I am planning on using OpenSSL for securing
I'm planning on building a feature for an e-commerce platform I developed in Java
I'm planning on building a file cataloging system. It will do something very similar
I am planning on building a 2D game library for XNA, and one of
I'm planning on building a Django log-viewing app with powerful filters. I'd like to
I'm planning on building a mySQL table that requires a student's name which looks
I am tasked with building a process which will compensate for replication delays on
I'm planning on building up a potentially large string by iterating over a collection
I'm building an app using Phonegap and I'm using Urban Airship for iOS and
We are planning on introducing simple Audit Trail in our database using triggers and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.