hey i am new here
i am working on a school project where i am building an applet..
i have encountered a problem i cant solve, i have 2 classes...
the first class i very simple it has to methods which return an string array for table column and Object that returns the date..
the second class has some methods in it... they all return a component which is a table, and that table is used in different classes to show for example customer transactions etc..
Everything is working BUT the table is not updating??
i have tried everything from firetablechange etcetc.... but nothing is working...
thank you all in advance.
FIRTS CLASS:
import java.sql.ResultSetMetaData;
public class tableData extends CustFunk {
public String[] colNamesTable(long custID, String query){
ResultSetMetaData rsmd = null;
String[] colNames = null;
try {
resultSet = statement.executeQuery(query);
rsmd = resultSet.getMetaData();
colNames = new String[rsmd.getColumnCount()];
for(int j = 0; j < rsmd.getColumnCount(); j++){
colNames[j] = rsmd.getColumnName(j+1);
}
}catch(Exception e){
e.printStackTrace();
}
return colNames;
}
public Object[][] dataTable(long custID, String query){
ResultSetMetaData rsmd = null;
Object[][] data = null;
try{
resultSet = statement.executeQuery(query);
rsmd = resultSet.getMetaData();
int rows = 0;
while(resultSet.next()){
rows++;
}
resultSet.beforeFirst();
data = new Object[rows][rsmd.getColumnCount()];
for(int i = 0; i < rows; i++){
resultSet.next();
for(int j = 0; j < rsmd.getColumnCount(); j++){
data[i][j] = resultSet.getObject(j+1);
}
}
}catch(Exception e){
e.printStackTrace();
}
return data;
}
}
SECOND CLASS
public class TableClass {
private JTable table;
private AbstractTableModel m;
private tableData td;
public Component displCustAccInfo(long custID, int x, int y, int width,
int height) {
td = new tableData();
String sql = "SELECT accounts.Account_Name, accounts.Saldo, "
+ "useraccounts.Account_NR"
+ " from Accounts "
+ "INNER JOIN useraccounts on accounts.Account_NR=useraccounts.Account_NR"
+ " AND useraccounts.Kunde_id=" + custID + ";";
// m = new DefaultTableModel(td.dataTable(custID, sql), td.colNamesTable(custID, sql));
table = new JTable(td.dataTable(custID, sql), td.colNamesTable(custID,
sql)) {
public boolean isCellEditable(int row, int column) {
return false;
}
};
//table.tableChanged(new TableModelEvent(table.getModel()));
// table.setModel(m);
table.setFont(new Font("Lucida Grande", Font.PLAIN, 14));
table.setBackground(UIManager
.getColor("CheckBoxMenuItem.selectionBackground"));
table.setForeground(Color.WHITE);
table.setBounds(x, y, width, height);
return table;
}
}
this is how i call the method in my GUI
public void actionPerformed(ActionEvent arg0) {
and from my customer GUI i call the method:
TableClass tc = new TableClass();
tc.displCustAccInfo(custID, 154, 550, 357, 91
}
}