Hello!

As a college assignment, I'm finishing a small applet that communicates with a MySQL database (through a Java server via RMI - all this is part of the assignment).

It's doing all it should except for one thing: in one of the tabs I included a JTable that lists all the records available in the database OR populates it based on a query, but I can't update it when I need to.

What I've already succeeded in doing: when the applet loads the JTable is populated with all the database records. Great!
What I'm getting desperate to learn how to do: update the JTable everytime I insert/delete/update records in the database.

I'm getting the info from the server though a String array (two dimensions).

This is the code I have for the JTable:

tabelaConsulta.setModel(new javax.swing.table.DefaultTableModel(data,Columnnames) {
    boolean[] canEdit = new boolean [] {false, false, false, false, false};
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit [columnIndex];
        }
    });
jScrollPane1.setViewportView(tabelaConsulta);

The table info is being carried by the variable data and Columnames is just an Array containing the names for the columns.

I'd really appreciate any ideas.
Thanks!

[]s
Marcos, Brazil.

Hello!

As a college assignment, I'm finishing a small applet that communicates with a MySQL database (through a Java server via RMI - all this is part of the assignment).

It's doing all it should except for one thing: in one of the tabs I included a JTable that lists all the records available in the database OR populates it based on a query, but I can't update it when I need to.

What I've already succeeded in doing: when the applet loads the JTable is populated with all the database records. Great!
What I'm getting desperate to learn how to do: update the JTable everytime I insert/delete/update records in the database.

I'm getting the info from the server though a String array (two dimensions).

This is the code I have for the JTable:

tabelaConsulta.setModel(new javax.swing.table.DefaultTableModel(data,Columnnames) {
    boolean[] canEdit = new boolean [] {false, false, false, false, false};
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit [columnIndex];
        }
    });
jScrollPane1.setViewportView(tabelaConsulta);

The table info is being carried by the variable data and Columnames is just an Array containing the names for the columns.

I'd really appreciate any ideas.
Thanks!

[]s
Marcos, Brazil.

From the above code it looks like you're instantiating an object and then creating some additional members within that object and overriding the method isCellEditable such that it will return your array of false so that nobody can ever access your table without your permission.

That's pretty cool, but what are the real reasons of why the DefaultTable is editable? Does a regular table that isEditable allow updates from a MySQL server?

I don't know to much about MySQL but is there a way to make the table run on a low-priority thread (or possibly a listener) and "listen" for an insert/delete/update records call which will reread information from the database and repopulate the JTable with the desired information?

You're using an anonymous inner class for the tablemodel.
That means you'll never be able to call any methods on it at a later time. That's not going to work as you want to change the content of the JTable.

This article has been dead for over six months. Start a new discussion instead.