wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes AbstractTableModel question (adding new record from DB) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "AbstractTableModel question (adding new record from DB)" Watch "AbstractTableModel question (adding new record from DB)" New topic

AbstractTableModel question (adding new record from DB)

Kristof Camelbeke
Ranch Hand

Joined: Nov 28, 2001
Posts: 97
I am trying to make an AbstractTableModel but I don't know how to add records from a database into this model.
In al the examples I have seen on the net they use Object[][] with initialized values.
Could somebody sent me an example of an AbstracTableModel that is used to deal with data from a Database ?
Below you can see what I have already ...

public class BestandTableModel extends AbstractTableModel {
String[] columnNames = {"Veldnaam","type","lengte Bytes","Beg Pos","Eind Pos"};
// this is for initialized data and cannot
// be used in my case !!
Object[][] data = {
{"Labonummer", "Numeric",new Integer(5),new Integer(1),new Integer(5)}


/** Creates new BestandTableModel */
public BestandTableModel() {
public String getColumnName(int col) {
return columnNames[col].toString();

public int getRowCount(){
// length is een variabele van een array
return data.length;

public int getColumnCount(){
return columnNames.length;

public Object getValueAt(int row, int column){
return data[row][column];

public boolean isCellEditable(int row, int col){
if (col == 0) {
return true ;
else {
return false;
Brian Snyder2002

Joined: Jan 24, 2002
Posts: 11
Take a look at this. You use an ArrayList to store the data and have a set list of column headings in you model class. When the data changes. Set the rrayList with the data, and have it fire an update. Good luck!!

Java Developer<br />SCJ2P
Kristof Camelbeke
Ranch Hand

Joined: Nov 28, 2001
Posts: 97
Ok thanks for the info
I'll take a close look at it
It is sorta covered in the JavaRanch Style Guide.
subject: AbstractTableModel question (adding new record from DB)
Similar Threads
JTable column help
Setting the value stored in collection Map to table cell
TableModel question
Reg Appending new row to already existing JTable
Problem Displaying JTable