• 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

How do I bind a ResultSet to a multiple columns TableModel?

 
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just can't handle this
ResultSet rs contains
1) Patient_ID, int
2) Patient_Name, String
3) Hospital_ID, int
4) Hospital_Name, String

I used to bind the database table to the JTable with rs2xml.jar. It was successful. But I'd like to make it sortable in every column.
Thanks a lot
Jack

 
Ranch Hand
Posts: 174
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. your AbstractTableModel isnt complete, Id to suggest to use DefaultTableModel instead

2. override get/setColumnNames in XxxTableModel, add with proper fireXxxXxx methods inside

3. override addRow, then each of loop inside JDBC should be called this methods

4. remove whatever about Comparator / Collator, those methods are implemented for JTables RowSorter and RowFilter correctly, AFAIK no Bugs there, :-) excluding one funny issue

5. use biult_in methods for RowSorter and RowFilter

6. remove MouseListener added to JTableHeader

7. use biult_in methods for RowSorter and RowFilter

8. there I cant see any reason for usage of AbstractTableModel, because nothing special methods arent there (in your code)

9. example about DefaultTableModel, change hardcoded addRow to JDBC

10. all updates to the Swing GUI, JTable and its model must be done on EDT, more in Concurency in Swing
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
would all updates to the table model instantly reflected in the database?
because I find out that if I add a row after retreiving the max id from the database, say 7, the same id will re-appear if I add another row to it
How do I save the table models into the database?
Tried CachedRowSet, but it requires a great deal of labour in changing all the code base of my current project

[Solved]
Any ideas?
Thanks
Jack
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now my problems being are
1) can't update the table after updating the database
2) can't update the jFreeChart after inserting/updating and deleting a record from the table and database



In theory, the JTable should be listening to the 3 JTextfields and 1 JComboBox, But I don't know how it should be done

Please help
 
Nothing up my sleeve ... and ... presto! A tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic