1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
private void AjouterActionPerformed(java.awt.event.ActionEvent evt) {
try {
// le numéro de la ligne selectionée
int i = jTableBB.getSelectedRow();
//récuperation des données
String selt = jTableBB.getValueAt(i, 0).toString();
String selet=jTableBB.getValueAt(i, 1).toString();
//Insertion dans la base de données (dans un table A)
con.Conn().executeUpdate("insert into A values ('"+selt+"','"+selet+"')");
// rechargement de la jtable A dans le jframe principale
Principale prin = new Principale();
ResultSet ResultRech = null;
DefaultTableModel aModel = (DefaultTableModel) prin.jTableAA.getModel();
aModel.getDataVector().removeAllElements();
{ ResultRech = con.Conn().executeQuery("select * from A");
ResultSetMetaData rsmd = null;
rsmd = ResultRech.getMetaData();
int cols = 0;
cols = rsmd.getColumnCount();
while (ResultRech.next())
{
Object[] row = new Object[cols];
for (int j = 0; j < row.length; j++) {
row[j] = ResultRech.getObject(j + 1); }
aModel.addRow(row);
}
prin.jTableAA.setModel(aModel);
prin.jTableAA.repaint();
this.dispose();//fermeture de jframe Secondaire
}}catch (SQLException | RemoteException ex) {
Logger.getLogger(B.class.getName()).log(Level.SEVERE, null, ex);
} |
Partager