Bouton de modification en Netbeans

Fermé
leopardntic Messages postés 1 Date d'inscription mardi 15 mars 2016 Statut Membre Dernière intervention 15 mars 2016 - Modifié par jordane45 le 16/03/2016 à 17:02
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 - 16 mars 2016 à 17:05
Bonjour toute le monde, j'ai problème avec mes boutons (modification, supprimer et recherche). Mon projet se connecte bien à la base de donnée pour afficher les informations enregistrer ou pour ajouter des information mais quand tu essaies de modifier il affiche ce message: You have an error in your SQL syntax, check the manual that corresponds to your Mysql server version for the right syntax to use near 'where id=' at line 1, pour supprimer c'est aussi:You have an error in your SQL syntax, check the manual that corresponds to your Mysql server version for the right syntax to use near 'Delet From stagaire where id=' at line 1.

Et voici mon code complet:

/*


* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/
package ega;

import java.awt.*;
import java.sql.Connection;
import javax.swing.*;
import javax.sql.*;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement.*;
import java.sql.Statement;
import java.util.Date;
import javax.swing.JOptionPane.*;
import javax.swing.JTextField.*;
import javax.swing.table.DefaultTableModel.*;
import javax.swing.table.DefaultTableModel;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *


* @author LEOPARD-NTIC2

*/
public class Controle extends javax.swing.JFrame {

    /**


* Creates new form Controle

*/
    private DefaultTableModel dt;
    private int id;
    private String matricule,nom, prenom;
            private String departement,contrat,duree,sexe,autre;
    //private JTextField txtid;
    private int i;// un indice de deplacement
    Connection con=null;
    Statement st=null;
    ResultSet rs=null;
   // private Object txtid;
    
    
    public Controle() {
        initComponents();
    }

    /**


* This method is called from within the constructor to initialize the form.

* WARNING: Do NOT modify this code. The content of this method is always

* regenerated by the Form Editor.

*/
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jrbg = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtcontrat = new javax.swing.JTextField();
        txtnom = new javax.swing.JTextField();
        txtprenom = new javax.swing.JTextField();
        txtid = new javax.swing.JTextField();
        txtrech = new javax.swing.JTextField();
        txtmatricule = new javax.swing.JTextField();
        comborech = new javax.swing.JComboBox();
        jrb2 = new javax.swing.JCheckBox();
        jrb3 = new javax.swing.JCheckBox();
        jrb1 = new javax.swing.JCheckBox();
        btn3 = new javax.swing.JButton();
        btn4 = new javax.swing.JButton();
        btn2 = new javax.swing.JButton();
        btn5 = new javax.swing.JButton();
        btn1 = new javax.swing.JButton();
        comb1 = new javax.swing.JComboBox();
        txtduree = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        autre1 = new javax.swing.JTextArea();
        jLabel13 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblestg = new javax.swing.JTable();
        jLabel15 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(1110, 660));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });
        getContentPane().setLayout(null);

        jLabel1.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
        jLabel1.setText("N° Mll:");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(40, 190, 70, 22);

        jLabel2.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
        jLabel2.setText("ID:");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(50, 150, 40, 22);

        jLabel3.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
        jLabel3.setText("Nom:");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(30, 220, 60, 22);

        jLabel4.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
        jLabel4.setText("Département:");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(10, 310, 130, 22);

        jLabel5.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
        jLabel5.setText("Prènom:");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(20, 270, 90, 22);

        jLabel6.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
        jLabel6.setText("Contrat:");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(20, 350, 90, 22);

        jLabel7.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
        jLabel7.setText("Sexe:");
        getContentPane().add(jLabel7);
        jLabel7.setBounds(10, 460, 60, 22);

        jLabel8.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
        jLabel8.setText("Durée de Service:");
        getContentPane().add(jLabel8);
        jLabel8.setBounds(0, 400, 170, 22);

        txtcontrat.setBackground(new java.awt.Color(153, 255, 102));
        txtcontrat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtcontratActionPerformed(evt);
            }
        });
        getContentPane().add(txtcontrat);
        txtcontrat.setBounds(150, 350, 140, 30);

        txtnom.setBackground(new java.awt.Color(153, 255, 102));
        getContentPane().add(txtnom);
        txtnom.setBounds(150, 220, 140, 30);

        txtprenom.setBackground(new java.awt.Color(153, 255, 102));
        getContentPane().add(txtprenom);
        txtprenom.setBounds(150, 270, 140, 30);

        txtid.setBackground(new java.awt.Color(153, 255, 102));
        getContentPane().add(txtid);
        txtid.setBounds(150, 140, 140, 30);

        txtrech.setBackground(new java.awt.Color(153, 255, 102));
        getContentPane().add(txtrech);
        txtrech.setBounds(350, 560, 110, 30);

        txtmatricule.setBackground(new java.awt.Color(153, 255, 102));
        getContentPane().add(txtmatricule);
        txtmatricule.setBounds(150, 180, 140, 30);

        comborech.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "N°MLL", "NOM", "PRENOM", "SEXE", "DEPARTEMENT" }));
        getContentPane().add(comborech);
        comborech.setBounds(350, 530, 110, 20);

        jrb2.setBackground(new java.awt.Color(255, 102, 102));
        jrb2.setText("Féminin");
        jrb2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb2ActionPerformed(evt);
            }
        });
        getContentPane().add(jrb2);
        jrb2.setBounds(170, 460, 81, 23);

        jrb3.setBackground(new java.awt.Color(255, 102, 102));
        jrb3.setText("Enfant");
        jrb3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb3ActionPerformed(evt);
            }
        });
        getContentPane().add(jrb3);
        jrb3.setBounds(260, 460, 80, 23);

        jrb1.setBackground(new java.awt.Color(255, 102, 102));
        jrb1.setText("Masculin");
        jrb1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb1ActionPerformed(evt);
            }
        });
        getContentPane().add(jrb1);
        jrb1.setBounds(80, 460, 80, 23);

        btn3.setBackground(new java.awt.Color(255, 255, 51));
        btn3.setFont(new java.awt.Font("Tahoma", 3, 14)); // NOI18N
        btn3.setText("Suprimer");
        btn3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                btn3MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                btn3MouseExited(evt);
            }
        });
        btn3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn3ActionPerformed(evt);
            }
        });
        getContentPane().add(btn3);
        btn3.setBounds(20, 580, 100, 25);

        btn4.setBackground(new java.awt.Color(255, 255, 51));
        btn4.setFont(new java.awt.Font("Tahoma", 3, 14)); // NOI18N
        btn4.setText("Actualiser");
        btn4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                btn4MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                btn4MouseExited(evt);
            }
        });
        btn4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn4ActionPerformed(evt);
            }
        });
        getContentPane().add(btn4);
        btn4.setBounds(130, 580, 100, 25);

        btn2.setBackground(new java.awt.Color(255, 255, 51));
        btn2.setFont(new java.awt.Font("Tahoma", 3, 14)); // NOI18N
        btn2.setText("Modifier");
        btn2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                btn2MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                btn2MouseExited(evt);
            }
        });
        btn2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn2ActionPerformed(evt);
            }
        });
        getContentPane().add(btn2);
        btn2.setBounds(130, 530, 100, 25);

        btn5.setBackground(new java.awt.Color(255, 255, 51));
        btn5.setFont(new java.awt.Font("Tahoma", 3, 14)); // NOI18N
        btn5.setText("Recheche");
        btn5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                btn5MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                btn5MouseExited(evt);
            }
        });
        btn5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn5ActionPerformed(evt);
            }
        });
        getContentPane().add(btn5);
        btn5.setBounds(350, 600, 110, 25);

        btn1.setBackground(new java.awt.Color(255, 255, 51));
        btn1.setFont(new java.awt.Font("Tahoma", 3, 14)); // NOI18N
        btn1.setText("Ajouter");
        btn1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                btn1MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                btn1MouseExited(evt);
            }
        });
        btn1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn1ActionPerformed(evt);
            }
        });
        getContentPane().add(btn1);
        btn1.setBounds(20, 530, 100, 25);

        comb1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "VEILLEZ CHOISIR LE DEPARTEMENT", "CLINIC", "Comptabilité", "IT", "SAFETY", "INGENERY", "MAGASIN", "LABO", "GEOLOGIE", " " }));
        getContentPane().add(comb1);
        comb1.setBounds(150, 310, 140, 30);

        txtduree.setBackground(new java.awt.Color(153, 255, 102));
        getContentPane().add(txtduree);
        txtduree.setBounds(170, 390, 120, 30);

        jLabel9.setFont(new java.awt.Font("Tahoma", 3, 14)); // NOI18N
        jLabel9.setText("Recherche par:");
        getContentPane().add(jLabel9);
        jLabel9.setBounds(240, 530, 120, 17);

        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ega/semos.jpg"))); // NOI18N
        getContentPane().add(jLabel11);
        jLabel11.setBounds(920, 0, 180, 170);

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ega/semos2.jpg"))); // NOI18N
        getContentPane().add(jLabel12);
        jLabel12.setBounds(10, 50, 87, 70);

        autre1.setBackground(new java.awt.Color(153, 255, 102));
        autre1.setColumns(20);
        autre1.setRows(5);
        autre1.setText("\n");
        jScrollPane2.setViewportView(autre1);

        getContentPane().add(jScrollPane2);
        jScrollPane2.setBounds(500, 530, 600, 96);

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel13.setText("Autre Information a ajouter:");
        getContentPane().add(jLabel13);
        jLabel13.setBounds(490, 510, 170, 14);

        tblestg.setBackground(new java.awt.Color(153, 255, 102));
        tblestg.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"", "", "", "", "", "", "", "", null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "ID", "Matricule", "NOM", "PRENOM", "DEPARTEMENT", "CONTRAT", "DUREE", "SEXE", "AUTRE INFOS"
            }
        ));
        tblestg.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblestgMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblestg);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(300, 190, 800, 260);

        jLabel15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ega/CLINIC.jpg"))); // NOI18N
        jLabel15.setMaximumSize(new java.awt.Dimension(1103, 640));
        getContentPane().add(jLabel15);
        jLabel15.setBounds(0, 20, 1100, 650);

        pack();
    }// </editor-fold>                        

    private void jrb2ActionPerformed(java.awt.event.ActionEvent evt) {                                     
sexe=jrb2.getText();        // TODO add your handling code here:
    }                                    

    private void jrb3ActionPerformed(java.awt.event.ActionEvent evt) {                                     
sexe=jrb3.getText();        // TODO add your handling code here:
    }                                    

    private void jrb1ActionPerformed(java.awt.event.ActionEvent evt) {                                     
sexe=jrb1.getText();        // TODO add your handling code here:
    }                                    

    private void btn1MouseEntered(java.awt.event.MouseEvent evt) {                                  
        // TODO add your handling code here:
        btn1.setBackground(new java.awt.Color(122,22,223));
    }                                 

    private void btn1MouseExited(java.awt.event.MouseEvent evt) {                                 
        // TODO add your handling code here:
        btn1.setBackground(new java.awt.Color(255,255,51));
    }                                

    private void btn2MouseEntered(java.awt.event.MouseEvent evt) {                                  
 btn2.setBackground(new java.awt.Color(122,22,223));        // TODO add your handling code here:
    }                                 

    private void btn3MouseEntered(java.awt.event.MouseEvent evt) {                                  
 btn3.setBackground(new java.awt.Color(122,22,223));        // TODO add your handling code here:
    }                                 

    private void btn4MouseEntered(java.awt.event.MouseEvent evt) {                                  
 btn4.setBackground(new java.awt.Color(122,22,223));        // TODO add your handling code here:
    }                                 

    private void btn5MouseEntered(java.awt.event.MouseEvent evt) {                                  
 btn5.setBackground(new java.awt.Color(122,22,223));        // TODO add your handling code here:
    }                                 

    private void btn2MouseExited(java.awt.event.MouseEvent evt) {                                 
 btn2.setBackground(new java.awt.Color(255,255,51));        // TODO add your handling code here:
    }                                

    private void btn3MouseExited(java.awt.event.MouseEvent evt) {                                 
 btn3.setBackground(new java.awt.Color(255,255,51));        // TODO add your handling code here:
    }                                

    private void btn4MouseExited(java.awt.event.MouseEvent evt) {                                 
 btn4.setBackground(new java.awt.Color(255,255,51));        // TODO add your handling code here:
    }                                

    private void btn5MouseExited(java.awt.event.MouseEvent evt) {                                 
 btn5.setBackground(new java.awt.Color(255,255,51));        // TODO add your handling code here:
    }                                

    private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  
        // TODO add your handling code here:
        try{
          Class.forName("com.mysql.jdbc.Driver");
            con=DriverManager.getConnection("jdbc:mysql://localhost:3306/stg1?zeroDateTimeBehavior=convertToNull","root","");
            st = con.createStatement();
            jrbg.add(jrb1);
    jrbg.add(jrb2);
    jrbg.add(jrb3);
    
    dt= new DefaultTableModel();
    dt.addColumn("id");
    dt.addColumn("mat");
    dt.addColumn("nom");
    dt.addColumn("prenom");
    dt.addColumn("departement");
    dt.addColumn("contrat");
    dt.addColumn("dure");
    dt.addColumn("sexe");
    dt.addColumn("autre");
    tblestg.setModel(dt);
           Afficher();
           i=0;
           Deplacer(i);
        }catch (Exception e){
            System.out.printf("erreur "+ e.getMessage());
            JOptionPane.showMessageDialog(null,"Erreur de connexion\n "+ e.getMessage());
        
        }
    }                                 

    private void txtcontratActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
    }                                          

    private void btn1ActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        try{
         String sql= "INSERT INTO stagaire(matricule,nom,prenom,departement, contrat,duree,sexe,autre)VALUES (?,?,?,?,?,?,?,?)";
         PreparedStatement ps= con.prepareStatement(sql);
        // ps.setString(1,txtid.getText());
         ps.setString(1,txtmatricule.getText());
          ps.setString(2,txtnom.getText());
           ps.setString(3,txtprenom.getText());
            ps.setString(4, comb1.getSelectedItem().toString());
            ps.setString(5,txtcontrat.getText());
             ps.setString(6, txtduree.getText());
            ps.setString(7, sexe);
              ps.setString(8,autre1.getText());
             
        //ps.executeQuery();
        ps.executeUpdate();
         Afficher();
         JOptionPane.showMessageDialog(null, "Ajouté");
        }catch(SQLException | HeadlessException e){
         JOptionPane.showMessageDialog(null,"Erreur d'ajouter un Patient ou Personnel\n"+e.getMessage());
        System.err.println(""+e.getMessage());
        }
    }                                    

    private void tblestgMouseClicked(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        try{
           i= tblestg.getSelectedRow();
           Deplacer(i);
        }catch (Exception e){
            JOptionPane.showMessageDialog(null, "Erreur de selectionné la liste\n"+e.getMessage());
            
        }
    }                                    

    private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        try{
           if(JOptionPane.showConfirmDialog(null, "Voulez-vous modifier le Patient?\n","Modification sur un Patient\n",JOptionPane.YES_NO_OPTION)== JOptionPane.OK_OPTION){
               st.executeUpdate("UPDATE stagaire SET matricule='"+txtid.getText()+"',nom= '"+txtnom.getText()+"',prenom='"+txtprenom.getText()+"', departement='"+comb1.getSelectedItem().toString()+"',contrat='"+txtcontrat.getText()+"',duree='"+txtduree.getText()+"',sexe='"+sexe
                       +"', autre= '"+autre1.getText()+"', where id="+txtid.getText());
               Afficher();
           } 
        }catch ( SQLException e){
            JOptionPane.showMessageDialog(null, "Erreur de Modifier les information selectionnées"+e.getMessage());
        }
        
    }                                    

    private void btn3ActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        try {
            if(JOptionPane.showConfirmDialog(null, "Attention souhaite-vous suprimer?","Suprimer Patient", JOptionPane.YES_NO_OPTION)
                    == JOptionPane.OK_OPTION)
            if (txtid.getText().length()!=0){
                st.executeUpdate("Delet From stagaire where id= "+txtid.getText()+"");
                Afficher();
            }
            //else { JOptionPane.showMessageDialog(null, "Veuillez remplire le champ id!");}
        }catch (SQLException e){
            JOptionPane.showMessageDialog(null, "Erreur de Suprimer\n"+e.getMessage());
        }
    }                                    

    private void btn4ActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        actualiser();
        Afficher();
    }                                    
     /*String combo{
    switch(combrech.getSelectedIndex()){
        case 0: return "id";
            case 1: return "matricule";
        case 2: return "nom";
        case 3: return "prenom";
        case 4: return "departement";
        case 5: return "sexe";
    }
    return "";
}*/
    private void btn5ActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        try{
          dt.setRowCount(0);
          Statement st= con.createStatement();
          ResultSet rs= st.executeQuery("select *from stagaire WHERE "+comborech+" like'§"+ txtrech.getText()+"§'");
        while(rs.next()){
            id= rs.getInt(1);
            matricule =rs.getString("matricule");
            nom= rs.getString(3);
            prenom = rs.getString(4);
            departement= rs.getString(5);
            contrat= rs.getString(6);
            duree= rs.getString(7);
            sexe= rs.getString(8);
            autre= rs.getString(9);
            Object[] stg1= {
                id, matricule, nom, prenom, departement, contrat, duree, sexe, autre
            };
              dt.addRow(stg1);           
        }
        if (dt.getRowCount()==0){
            JOptionPane.showMessageDialog(null, "Aucun Patient");
            Afficher();
        }
        else {
            i=0;
            Deplacer(i);
        }
        }catch (Exception e){
          JOptionPane.showMessageDialog(null, ""+e.getMessage());
          System.err.println(e);
        }
    }                                    
      
    private void Afficher() {
        txtid.setEnabled(true);
        try{
            dt.setRowCount(0);
            rs= st.executeQuery("select *from stagaire");
            while(rs.next()){
                id=rs.getInt("id");
                matricule=rs.getString("matricule");
                 nom=rs.getString("nom");
                 prenom=rs.getString("prenom");
                   departement=rs.getString("departement");
                    contrat=rs.getString("contrat");
                     duree=rs.getString("duree");
                      sexe=rs.getString("sexe");
                       autre=rs.getString("autre");
                  Object[] t={
                      id,matricule,nom,prenom,departement,contrat,duree,sexe,autre
                  };
                  dt.addRow(t);
                    }
        }catch(Exception e){
            JOptionPane.showMessageDialog(null,"Erreur d'afficher la liste des Stagaires\n"+e.getMessage());
        }
    }
    public void actualiser(){
        txtid.setText("");
        txtnom.setText("");
        txtprenom.setText("");
        comb1.setSelectedItem("");
        txtduree.setText("");
        jrb3.isSelected();
        autre1.setText("");
        
    }
    public void Deplacer(int i){
        try{
            txtid.setText(dt.getValueAt(i,0).toString());
            txtmatricule.setText(dt.getValueAt(i, 1).toString());
            txtnom.setText(dt.getValueAt(i,2).toString());
            txtprenom.setText(dt.getValueAt(i,3).toString());
           comb1.setSelectedItem(dt.getValueAt(i,4).toString());
            txtcontrat.setText(dt.getValueAt(i,5).toString());
            
            txtduree.setText(dt.getValueAt(i,6).toString());
            
            autre1.setText(dt.getValueAt(i,8).toString());
            String s= dt.getValueAt(i, 7).toString();
            if(s.equals("masculin")){jrb1.setSelected(true);} else if(s.equals("Féminin")){jrb2.setSelected(true);}
                else if(s.equals("Enfant")){jrb3.setSelected(true);}
        }catch (Exception e){
            JOptionPane.showMessageDialog(null,"Erreur du deplacement du Patient\n"+e.getMessage());
        }
    }
    /**


* @param args the command line arguments

*/
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.


* For details see [http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html] 

*/
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Controle.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Controle.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Controle.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Controle.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(() -> {
            new Controle().setVisible(true);
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JTextArea autre1;
    private javax.swing.JButton btn1;
    private javax.swing.JButton btn2;
    private javax.swing.JButton btn3;
    private javax.swing.JButton btn4;
    private javax.swing.JButton btn5;
    private javax.swing.JComboBox comb1;
    private javax.swing.JComboBox comborech;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JCheckBox jrb1;
    private javax.swing.JCheckBox jrb2;
    private javax.swing.JCheckBox jrb3;
    private javax.swing.ButtonGroup jrbg;
    private javax.swing.JTable tblestg;
    private javax.swing.JTextField txtcontrat;
    private javax.swing.JTextField txtduree;
    private javax.swing.JTextField txtid;
    private javax.swing.JTextField txtmatricule;
    private javax.swing.JTextField txtnom;
    private javax.swing.JTextField txtprenom;
    private javax.swing.JTextField txtrech;
    // End of variables declaration                   

/*    private void Afficher() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }*/
}
 


SVP AIDER MOI!!!!!


EDIT : Ajout des balises de code (la coloration syntaxique).
Explications disponibles ici :ICI

Merci d'y penser dans tes prochains messages.

2 réponses

jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650
16 mars 2016 à 17:05
Et pour celle la :
  st.executeUpdate("Delet From stagaire where id= "+txtid.getText()+"");

N'aurais tu pas oublié un "E" au mot DELETE ??
1
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650
16 mars 2016 à 17:04
Bonjour,

 st.executeUpdate("UPDATE stagaire SET matricule='"+txtid.getText()+"',nom= '"+txtnom.getText()+"',prenom='"+txtprenom.getText()+"', departement='"+comb1.getSelectedItem().toString()+"',contrat='"+txtcontrat.getText()+"',duree='"+txtduree.getText()+"',sexe='"+sexe
                       +"', autre= '"+autre1.getText()+"', where id="+txtid.getText());

N'aurais-tu pas une virgule en trop avant le WHERE ??
0