This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
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

Win a copy of Elasticsearch in Action this week in the Big Data forum!
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
I agree. Here's the link:
subject: AbstractTableModel question (adding new record from DB)