Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

updating a JTree from a database

 
Kaushik Gopal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic