I am trying to update database by editing cell values in jtable. my table looks like a

When i edit the value in particular cell and without clicking anywhere if i click on Update button the database is not updated as like this !
but if i click somewhere in the updating row, which again turns the look of table as fig. 1 then the database is upodated with particular value, why is this happening please help. My code for refresh Button goes like this:

        int pos = recordTable.getSelectedRow();
        int id = (Integer) recordTable.getModel().getValueAt(pos, 0);

        ListSelectionModel selectionModel = recordTable.getSelectionModel();
        selectionModel.setSelectionInterval(pos, pos);

        String roomName = (String) recordTable.getValueAt(pos, 1);
        int roomCharge = Integer.parseInt(recordTable.getModel().getValueAt(pos, 2).toString());
        System.out.println(id + roomName + roomCharge);
        admin.updateRoomType(id, roomName, roomCharge);

please help!!

Edited by 47pirates

Attachments b.JPG 15.06 KB
6 Years
Discussion Span
Last Post by dougWill

Sorry my English is not very good, but I use Netbeans to retrieve information from the cell use this code:

 DefaultTableModel dtm1 = (DefaultTableModel) jTable1.getModel();
 dtm1.getValueAt(i, 2).toString();

Are you sure about the database update? Maybe your update button is updating the database, but there's no code to update the JTable at that point, so you don't see that it's updated? Then when you do anything that causes a repaint of the JTable you see the new data?


The code I posted is to take the data of JTable, so you can show on a JOptionPane.ShowMessage so you will see if the code is correct. After inserting it in the database with SQL

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.