Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AbstractTableModel question (adding new record from DB)

 
Kristof Camelbeke
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
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 ...
Thanks....
Kristof


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
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
Kristof Camelbeke
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks for the info
I'll take a close look at it
Kristof
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic