1

I am writing a desktop application in Java and it uses two JTables as the main output.

I have a working version of the program where I use DefaultTableModels to manage the underlying data of the JTables and I use an ArrayList to store the data in each model.

However, I've come across the ResultSetTableModel which stores the data in a ResultSet and a ResultSetMetaData object to implement the TableModel methods.

But I am not clear on the benefits of using a ResultSetTableModel as opposed to a DefaultTableModel or AbstractTableModel. I have searched and I cannot find any discussion on this.

Does anyone know why one would favor a ResultSetTableModel over the other options?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
JDJ
  • 4,298
  • 3
  • 25
  • 44

1 Answers1

0

if you use DefaultTableModel you have to store the data into model manually, and if you ResultSetTableModel data automatically loads into JTable this is the difference.

SuRu
  • 739
  • 1
  • 6
  • 19
  • I just did some more research and wrote a small program that uses a ResultSetTableModel, and the main difference seems to be that, with a ResultSetTableModel, whenever you update the model, you're updating the resultset, and that change is immediately reflected in the underlying database. (As long as you set the ResultSet.CONCUR_UPDATABLE flag when creating the Statement object.) But when you use either a DefaultTableModel or an AbstractTableModel that stores the model data in something like a 2D ArrayList, you have to code separate SQL calls to update the underlying database tables. – JDJ Dec 30 '13 at 19:46