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.


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){

		return colNames;
		public Object[][] dataTable(long custID, String query){
			ResultSetMetaData rsmd = null; 
			 Object[][] data = null;
				resultSet = statement.executeQuery(query); 
				rsmd = resultSet.getMetaData();
				int rows = 0;
        data = new Object[rows][rsmd.getColumnCount()];
        for(int i = 0; i < rows; i++){
                for(int j = 0; j < rsmd.getColumnCount(); j++){
                        data[i][j] = resultSet.getObject(j+1);
			}catch(Exception e){
			return data;



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.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



Recommended Answers

Adding a Table to a Container
SimpleTableDemo.java as example

Jump to Post

Typical problem for DownloadManager's..... Read this stuff but only table code...

Jump to Post

All 5 Replies

1/ read tutorial linked by quuba
2/ especially about DefaultTableModel
3/ don't create table inside Sql statement, don't do that
4/ follows with examples from JTable tutorial
5/ read turorial about JDBC http://download.oracle.com/javase/tutorial/index.html
6/ tons (runnable) example at http://www.java2s.com/ just put those together
7/ search for ResultSetTableModel or TableFromDatabase

thank you, but i dont understand how to implement that

1st. tutorial is about JTable, better tutorial about other JComponent(s) doesn't exist,

2nd. about JDBC is good too,

agreed just put these together ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.