• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A question about JTable and populating a DB

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic