Java code
int dialogDelete=JOptionPane.showConfirmDialog(null,"Are you sure you want to delete this Personnel?", "DELETE PERSONNEL",JOptionPane.YES_NO_OPTION);
if(dialogDelete==JOptionPane.YES_OPTION){
DefaultTableModel model = (DefaultTableModel)tbl_personnel.getModel();
int row = tbl_personnel.getSelectedRow();
String url = "jdbc:mysql://localhost/mypos";
String username = "root";
String password = "";
try {
Connection connection = DriverManager.getConnection(url,username,password);
System.out.println("database connected");
stmt = connection.createStatement();
stmt.execute("DELETE FROM Personnel WHERE Id ="+row+"");
} catch(Exception e) {
throw new IllegalStateException("cannot",e);
}
int modelRow = tbl_personnel.convertRowIndexToModel( row );
model.removeRow( modelRow );
}
I've edited the code. I can now delete the row in JTable and delete a row in mysql but the row that is deleted in JTable is not the row that is deleted in mysql. I'm not sure what's wrong.