File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes JTree data from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JTree data from database" Watch "JTree data from database" New topic

JTree data from database

Wynn Teoh

Joined: Dec 04, 2009
Posts: 10
Hi all,

I'm working on the example at

I wanted to customize it in a way the data are pulled from a table instead (folder_id, folder_name, parent_id[foreign key to determine parent] .
Here is my code

If I hardcode it as Person a1 = new Person("Jack (great-granddaddy)"); , it works fine. However, I wanted to put it in a loop, with the variable i :-

How can I make the variable i and the "a" to be combined together? In PHP, we usually combine them with a "." , eg "a".$i;

Thanks Any other example on creating trees from database is greatly appreciated too. Thanks in advance
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

So you want an array of Person objects? You already used an array in the line just above that, so it looks like you might already have some idea about arrays.
Wynn Teoh

Joined: Dec 04, 2009
Posts: 10

Thanks for your reply. I roughly work on the array from some examples. Don't really know if I'm doing it correctly

Do you mean that the Person objects have to be in array, and not in a loop like what I;m doing now? I want to have the variable "a1","a2","a3"... dynamically. Is it possible?
Thank you!
Wynn Teoh

Joined: Dec 04, 2009
Posts: 10
Just to add in more info, the example given looks somehting like this :

Then the trees will be in a hierarchy
I agree. Here's the link:
subject: JTree data from database
It's not a secret anymore!