I write this code and it run correctly but without deletting any row from jTable!!!I will be crazy!!!
the code is :
JTable tableau;
public void supprimerCompte(JTable tableau){
try {
int lign= tableau.getSelectedRow();
Statement stmt = C.createStatement();
stmt.executeUpdate("DELETE FROM Compte WHERE Indice ="+lign);
System.out.println("voila c'est fait");
tableau.removeRowSelectionInterval(lign, lign);
tableau.revalidate();
}
catch (SQLException ex) {
System.out.println("Erreur de suppression du compte.");
ex.printStackTrace();
JOptionPane.showMessageDialog(null,ex.getMessage());
}
}
And : private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
ConnPorCreationCompte C = new ConnPorCreationCompte();
C.supprimerCompte(jTable2);
jTable2.revalidate();
repaint();
}
After runnig I foud this result: "voila c'est fait"
Please I don't know were is the pb!!!
Please i need help,Please
I don't see any code that removes anything from the JTable. You remove the record from the database, then call tableau.removeRowSelectionInterval(lign, lign); which only de-selects the row. It doesn't remove anything.
To remove a row from a JTable you should use a TableModel that supports removal (like DefaultTableModel) and remove the row from it.