It would be easy to form a query to get desired result.A folder can have any number of child folders hence one query would not suffice.
you can go for self join and in oracle connect by prior clause to form a query but You will have to play with
java and queries both .
I haven't tried this but this is first thought in my mind If I were to solve this problem I would have added one more column to database let say depth of folder 0 for root folder 1 for first child 2 for next and so on ....then I would have form a binary tree with delp of folder depth then a infix notation of binary tree would result in a path of folder.
can you tell me which database are you using ?
Shailesh