aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How do I bind a ResultSet to a multiple columns TableModel? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How do I bind a ResultSet to a multiple columns TableModel?" Watch "How do I bind a ResultSet to a multiple columns TableModel?" New topic
Author

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

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 590
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

m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 155
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

Joined: Aug 02, 2012
Posts: 590
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

Joined: Aug 02, 2012
Posts: 590
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I bind a ResultSet to a multiple columns TableModel?