Partage
  • Partager sur Facebook
  • Partager sur Twitter

Erreur de connexion Login

Erreur de syntaxe pres de WHERE

    5 mars 2022 à 21:02:52

    bonjour chère membre, je suis nouveau dans le développement java et je suis bloque sur ma fentre LOGIN qui affiche de message d'erreur de la syntaxe vérification des données saisies.

    package Base_de_donnee;

    import Application.BDD;

    import Application.parameter;

    import java.sql.*;

    import java.sql.SQLException;

    import java.util.logging.Level;

    import java.util.logging.Logger;

    import javax.swing.JOptionPane;

    public class Login extends javax.swing.JFrame {

       //declarations

        ResultSet rs;

            BDD db;

            String username1, password1, hak;

        public Login() {

        db = new BDD(new parameter().HOST_DB, new parameter().USERNAME_DB, new parameter()

                .PASSWORD_DB, new parameter().IPHOST, new parameter().PORT);   

            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() {

            jLabel1 = new javax.swing.JLabel();

            jLabel2 = new javax.swing.JLabel();

            txt_username = new javax.swing.JTextField();

            jLabel3 = new javax.swing.JLabel();

            txt_password = new javax.swing.JTextField();

            jButton1 = new javax.swing.JButton();

            jButton2 = new javax.swing.JButton();

            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

            getContentPane().setLayout(null);

            jLabel1.setFont(new java.awt.Font("Times New Roman", 3, 48)); // NOI18N

            jLabel1.setText("LOGIN");

            getContentPane().add(jLabel1);

            jLabel1.setBounds(210, 30, 169, 59);

            jLabel2.setFont(new java.awt.Font("Times New Roman", 3, 24)); // NOI18N

            jLabel2.setText("User Name    :");

            getContentPane().add(jLabel2);

            jLabel2.setBounds(42, 133, 167, 40);

            txt_username.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N

            getContentPane().add(txt_username);

            txt_username.setBounds(329, 135, 178, 40);

            jLabel3.setFont(new java.awt.Font("Times New Roman", 3, 24)); // NOI18N

            jLabel3.setText("Password       :");

            getContentPane().add(jLabel3);

            jLabel3.setBounds(42, 217, 157, 39);

            txt_password.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N

            getContentPane().add(txt_password);

            txt_password.setBounds(329, 217, 178, 39);

            jButton1.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N

            jButton1.setText("Login");

            jButton1.addActionListener(new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent evt) {

                    jButton1ActionPerformed(evt);

                }

            });

            getContentPane().add(jButton1);

            jButton1.setBounds(110, 340, 130, 50);

            jButton2.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N

            jButton2.setText("Fermer");

            jButton2.addActionListener(new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent evt) {

                    jButton2ActionPerformed(evt);

                }

            });

            getContentPane().add(jButton2);

            jButton2.setBounds(310, 340, 110, 50);

            pack();

        }// </editor-fold>                        

        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         

            dispose();

        }                                        

        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        rs = db.querySelectAll("utilisateur", "username='" + txt_username.getText() + "' and password='" + txt_password.getText() + "'");

            try {

                while (rs.next()) {

                    username1 = rs.getString("username");

                    password1 = rs.getString("password");

                    hak = rs.getString("type");

                }

            } catch (SQLException ex) {

                Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);

            }

            if (username1 == null && password1 == null) {

                JOptionPane.showMessageDialog(this, "le nom utilisateur ou le mots de pass est incorrect");

            } else {

                if (hak.equals("directeur")) {

                    Principale h = new Principale();

                    h.setVisible(true);

                    this.dispose();

                } else {

                    Caissier k = new Caissier();

                    k.setVisible(true);

                    this.dispose();

                }

            }

        }                                        

        /**

         * @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(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

            } catch (InstantiationException ex) {

                java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

            } catch (IllegalAccessException ex) {

                java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

            } catch (javax.swing.UnsupportedLookAndFeelException ex) {

                java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

            }

            //</editor-fold>

            /* Create and display the form */

            java.awt.EventQueue.invokeLater(new Runnable() {

                public void run() {

                    new Login().setVisible(true);

                }

            });

        }

        // Variables declaration - do not modify                     

        private javax.swing.JButton jButton1;

        private javax.swing.JButton jButton2;

        private javax.swing.JLabel jLabel1;

        private javax.swing.JLabel jLabel2;

        private javax.swing.JLabel jLabel3;

        private javax.swing.JTextField txt_password;

        private javax.swing.JTextField txt_username;

        // End of variables declaration                   

    }

    Merci d'avance.
    • Partager sur Facebook
    • Partager sur Twitter
      5 mars 2022 à 21:07:42

      Bonjour,

      Le message qui suit est une réponse automatique activée par un membre de l'équipe. Les réponses automatiques leur permettent d'éviter d'avoir à répéter de nombreuses fois la même chose, ce qui leur fait gagner du temps et leur permet de s'occuper des sujets qui méritent plus d'attention.
      Nous sommes néanmoins ouverts et si vous avez une question ou une remarque, n'hésitez pas à contacter la personne en question par Message Privé.

      Pour plus d'informations, nous vous invitons à lire les règles générales du forum

      Merci de colorer votre code à l'aide du bouton Code

      Les forums d'Openclassrooms disposent d'une fonctionnalité permettant de colorer et mettre en forme les codes source afin de les rendre plus lisibles et faciles à manipuler par les intervenants. Pour cela, il faut utiliser le bouton Code de l'éditeur, choisir un des langages proposés et coller votre code dans la zone prévue. Si vous utilisez l'éditeur de messages en mode Markdown, il faut utiliser les balises <pre class="brush: java;">Votre code ici</pre>.

      Merci de modifier votre message d'origine en fonction.

      Liens conseillés

      • Partager sur Facebook
      • Partager sur Twitter
        5 mars 2022 à 21:15:32

        package Base_de_donnee;
        
        import Application.BDD;
        import Application.parameter;
        import java.sql.*;
        import java.sql.SQLException;
        import java.util.logging.Level;
        import java.util.logging.Logger;
        import javax.swing.JOptionPane;
        
        public class Login extends javax.swing.JFrame {
        
           //declarations
            
            ResultSet rs;
                BDD db;
                String username1, password1, hak;
                
                
            
            public Login() {
                
            db = new BDD(new parameter().HOST_DB, new parameter().USERNAME_DB, new parameter()
                    .PASSWORD_DB, new parameter().IPHOST, new parameter().PORT);   
                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() {
        
                jLabel1 = new javax.swing.JLabel();
                jLabel2 = new javax.swing.JLabel();
                txt_username = new javax.swing.JTextField();
                jLabel3 = new javax.swing.JLabel();
                txt_password = new javax.swing.JTextField();
                jButton1 = new javax.swing.JButton();
                jButton2 = new javax.swing.JButton();
        
                setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
                getContentPane().setLayout(null);
        
                jLabel1.setFont(new java.awt.Font("Times New Roman", 3, 48)); // NOI18N
                jLabel1.setText("LOGIN");
                getContentPane().add(jLabel1);
                jLabel1.setBounds(210, 30, 169, 59);
        
                jLabel2.setFont(new java.awt.Font("Times New Roman", 3, 24)); // NOI18N
                jLabel2.setText("User Name    :");
                getContentPane().add(jLabel2);
                jLabel2.setBounds(42, 133, 167, 40);
        
                txt_username.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
                getContentPane().add(txt_username);
                txt_username.setBounds(329, 135, 178, 40);
        
                jLabel3.setFont(new java.awt.Font("Times New Roman", 3, 24)); // NOI18N
                jLabel3.setText("Password       :");
                getContentPane().add(jLabel3);
                jLabel3.setBounds(42, 217, 157, 39);
        
                txt_password.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
                getContentPane().add(txt_password);
                txt_password.setBounds(329, 217, 178, 39);
        
                jButton1.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
                jButton1.setText("Login");
                jButton1.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        jButton1ActionPerformed(evt);
                    }
                });
                getContentPane().add(jButton1);
                jButton1.setBounds(110, 340, 130, 50);
        
                jButton2.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
                jButton2.setText("Fermer");
                jButton2.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        jButton2ActionPerformed(evt);
                    }
                });
                getContentPane().add(jButton2);
                jButton2.setBounds(310, 340, 110, 50);
        
                pack();
            }// </editor-fold>                        
        
            private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
                dispose();
            }                                        
        
            private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
                
            rs = db.querySelectAll("utilisateur", "username='" + txt_username.getText() + "' and password='" + txt_password.getText() + "'");
                try {
                    while (rs.next()) {
                        username1 = rs.getString("username");
                        password1 = rs.getString("password");
                        hak = rs.getString("type");
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
                }
        
                if (username1 == null && password1 == null) {
                    JOptionPane.showMessageDialog(this, "le nom utilisateur ou le mots de pass est incorrect");
                } else {
                    if (hak.equals("directeur")) {
                        Principale h = new Principale();
                        h.setVisible(true);
                        this.dispose();
                    } else {
                        Caissier k = new Caissier();
                        k.setVisible(true);
                        this.dispose();
                    }
                }
            }                                        
        
            /**
             * @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(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                } catch (InstantiationException ex) {
                    java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                    java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                }
                //</editor-fold>
        
                /* Create and display the form */
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        new Login().setVisible(true);
                    }
                });
            }
        
            // Variables declaration - do not modify                     
            private javax.swing.JButton jButton1;
            private javax.swing.JButton jButton2;
            private javax.swing.JLabel jLabel1;
            private javax.swing.JLabel jLabel2;
            private javax.swing.JLabel jLabel3;
            private javax.swing.JTextField txt_password;
            private javax.swing.JTextField txt_username;
            // End of variables declaration                   
        }
         
        
        • Partager sur Facebook
        • Partager sur Twitter
          7 mars 2022 à 11:39:57

          et "je bloque", ça veut dire quoi ?

          • Partager sur Facebook
          • Partager sur Twitter

          Erreur de connexion Login

          × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
          × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
          • Editeur
          • Markdown