aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes updating a JTree from a database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "updating a JTree from a database" Watch "updating a JTree from a database" New topic
Author

updating a JTree from a database

Kaushik Gopal
Greenhorn

Joined: Aug 20, 2001
Posts: 4
I am designing a java email client. I have used a JTree to display my folders (i.e. Inbox, Outbox, Sent Items etc.). The actual JTree comes up fine as i have created it with static strings. I now want to update the tree using values from a table in my mysql database which contains attributes - username, foldername.
If I get the foldernames using db.getfoldername where username = n, then how do I update the Jtree with these results? Pls help...deadline on the 7th of sept!. Thanks!
Raf Van de Plas
Greenhorn

Joined: Aug 29, 2001
Posts: 13
I don't have experience with mySQL-databases but I presume your working with the JDBC-classes. If that's the case you should get a ResultSet returned for any Statement (SELECT * FROM...) you throw at the database.
Construct a method that build a treemodel according to a resultset you pass it and call this method either when you know something has changed (when the database notifies you) or at predefined times (polling).
Simply run throught each record in the resultset and construct nodes as necessary. Then pass this model to the JTree via its setModel() method.
Hope this helps...
------------------
Vinod Venugopal
Ranch Hand

Joined: Dec 06, 2000
Posts: 148
Or you could use an ASP to query the database & get the result in string format separated by delimiters, which you can remove using tokenizer. Then with the updated treemodel u can regenerate the tree.


- Vinod<br />-------<br />SCJP2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: updating a JTree from a database
 
Similar Threads
JTree
JTree
collapsing JTree
JTree
Searching a JTree