aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes A question about JTable and populating a DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "A question about JTable and populating a DB" Watch "A question about JTable and populating a DB" New topic
Author

A question about JTable and populating a DB

Mahmoud Hadad
Ranch Hand

Joined: Jan 09, 2006
Posts: 67
Hi all,
guys i'm so confused about this.do i need to implement my own model to extract data from my DB ?
is there is anyway beside using the setValueAt()method and change the row ,index and value to extract data from my DB ?because it seems to me alot of overhead which will affect my App perfomrance?
i want to extract data from a result set object and show it in a JTable.so is there is anyway i can make a direct connection between the JDBC and JTable?
Kai Witte
Ranch Hand

Joined: Jul 17, 2004
Posts: 354
hello,

the more direct (coupled) this connection between table visualization and database table is, the less flexible and maintainable and the more complicated it is.

In many cases a logical record is stored as a row in a table. You would have an interface for that type, for example Person or Animal or House or Book. Your data tier should be designed independently from the presentation tier. Most likely the best choice is to use a persistence framework, for example Hibernate, but you can also implement all on your own, for example by using a DAO. Either way it is quite simple in most cases.

Create a custom TableModel. The simples way to do that is to extend AbstractTableModel, although one could argue about the purity of that approach. Implement the abstract methods of AbstractTableModel appropriately, and add a method to add a record of the type mentioned above (addPerson(Person p) or addAnimal(Animal a) or ...). Maybe you also need a method to get a record at a particular index?

And that's all.

Kai


Kai Witte's business website Kai Witte's private homepage Mock exam / preparation kit reviews
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A question about JTable and populating a DB
 
Similar Threads
JTable
JTable
cells in Jtable
JTable(!!!)
JTable