binding a db to a JTable
I want to update the underlying TableModel as per:
http://java.sun.com/docs/books/tutorial/uiswing/components/
table.html#modelchange
and then have that change percolate down to the db. Or, should that
happen in reverse? Change the db, then the TableModel, then update the
view?
thufir@arrakis:~/bcit3621$
thufir@arrakis:~/bcit3621$ head -n 137 crud/src/a00720398/view/View.java
| tail -n 14
public void tableChanged(TableModelEvent evt) {
int row = evt.getFirstRow();
int column = evt.getColumn();
TableModel model = (TableModel) evt.getSource();
String columnName = model.getColumnName(column);
Object data = model.getValueAt(row, column);
/*now that the user has changed the text
* of a field for a record, how to get
* that change reflected in the db. SQL?
* Then, the db calls notify() to let the
* TableModel know that it should update?
*/
}
thufir@arrakis:~/bcit3621$
thufir@arrakis:~/bcit3621$ cat crud/src/a00720398/model/CarModel.java
package a00720398.model;
import a00720398.model.*;
import a00720398.view.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import javax.swing.*;
import javax.swing.table.*;
@SuppressWarnings({"serial", "unchecked"})
public class CarModel extends DefaultTableModel implements Observer {
private static final TableModel INSTANCE = new CarModel();
private CarModel() {
this.dataVector = Model.getInstance().getDataVector();
this.columnIdentifiers = Model.getInstance().getColumnIdentifiers
();
}
public static TableModel getInstance() {
return INSTANCE;
}
public void update(Observable arg0, Object arg1) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
thufir@arrakis:~/bcit3621$
thanks,
Thufir