0

Im trying to remove row from java connected to database using this code

String sql="delete from buku where kode_buku=?";
int viewIndex = tabelDaftarBuku.getSelectedRow();

if(viewIndex != -1) 
{
    int modelIndex = tabelDaftarBuku.convertRowIndexToModel(viewIndex); 
    DefaultTableModel model2 = (DefaultTableModel)tabelDaftarBuku.getModel();
    model2.removeRow(modelIndex);
}

try {
    PreparedStatement pst=koneksi.prepareStatement(sql);
    pst.setString(1, jTKode1.getText());
    pst.execute();
    JOptionPane.showMessageDialog(null, "Deleted");
} catch(Exception e) {
    JOptionPane.showMessageDialog(null, e.getMessage());
}

The row is deleted when i check in the database but the java table stays the same and does not update unless i re-open it. Been trying to try to solve this but still has no idea, please help...

Marcel
  • 1,443
  • 2
  • 14
  • 24

0 Answers0