jtable question
hey all
i just wanna know...what is the most efficient way to add values from a database to a jtable....lets say i have a table in a database that have around 15000 tuple and i need to add those to a table in a jpanel....is a for loop with a body calling the method setvalueAt(Object data, int row, int column) a good and efficient way to do things ?
help please...
Thanks in advance
[408 byte] By [
bif_fa] at [2007-11-27 4:14:55]

# 2
class CustomerListGUITableModel extends AbstractTableModel {
int row = 1;
int column = 0;
private String[] columnNames = {"Name",
"Phone",
"Address",
"Note"};
private Object[][] data = {
{" ",
" ", " ", " "}
};
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return data.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
/*
* JTable uses this method to determine the default renderer/
* editor for each cell. If we didn't implement this method,
* then the last column would contain text ("true"/"false"),
* rather than a check box.
*/
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
/*
* Don't need to implement this method unless your table's
* data can change.
*/
public void setValueAt(Object value, int row, int col) {
data[row][col] = value;
}
public int getRow() {
return row;
}
public int getColumn() {
return column;
}
public void incRow() {
if (row == getRowCount()) {
System.err.println("Reached Bounds...");
} else
row++;
}
public void incColum() {
if(column == getColumnCount()){
System.err.println("Reached Bounds...");
}else
column++;
}
public void decRow(){
if(row == 1){
System.err.println("Reached Bounds...");
}else
row--;
}
public void decColumn(){
if(column == 0){
System.err.println("Reached Bounds...");
}else
column--;
}
public void setRow(int value) {
if(value<1){
System.err.println("row value must be greater or equal to 1");
return;
}
if(value > getRowCount()){
System.err.println("value entered must be within bounds");
return;
}
row = value;
}
public void setColumn(int value) {
if(column < 0){
System.err.println("column value must be greater or equal to 0");
return;
}
if(value > getColumnCount()){
System.err.println("value entered must be within bounds");
return;
}
column = value;
}
}
this is my table model....should i update the data object as i get values from the database ?
and after updating the data object i write something like table.setModel(new CustomerListGUITableModel()); ?
please help