• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

deleting row from jTable

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Please i need help!!!

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


 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic