Problème de login

christian3wilfried1 Messages postés 1 Date d'inscription dimanche 17 avril 2016 Statut Membre Dernière intervention 17 avril 2016 - Modifié par KX le 17/04/2016 à 21:01
choukie12 Messages postés 55 Date d'inscription vendredi 11 mars 2016 Statut Membre Dernière intervention 27 juin 2018 - 20 avril 2016 à 16:37
Bonjour! J'ai un problème de connexion à la base données au niveau de
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
j'arrive pas à me connecter à la base de données.Le code précendent est souligné en rouge. SVP aidez moi
voici le code dans son entier:

package base_de_données;

import Application.BDD;
import Application.Parametres;
import com.sun.istack.internal.logging.Logger;
import java.sql.*;
import java.util.logging.Level;
import javax.swing.JOptionPane;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class Login extends javax.swing.JFrame {

    //Déclararion
    ResultSet rs;
    BDD db;
    String username1, password1, hak;
    
    public Login() {
        db = new BDD(new Parametres().HOST_DB,new Parametres().USERNAME_DB, new Parametres().PASSWORD_DB, 
                new Parametres().IPHOST, new Parametres().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();
        jLabel3 = new javax.swing.JLabel();
        txt_password = new javax.swing.JTextField();
        jLabel = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        txt_username1 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        jLabel1.setFont(new java.awt.Font("Tw Cen MT Condensed Extra Bold", 3, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 204, 255));
        jLabel1.setText("   LOGIN");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(130, 10, 110, 50);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("MOT DE PASSE :");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(10, 150, 130, 40);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setText("UTILISATEUR :");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(20, 68, 120, 40);

        txt_password.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        getContentPane().add(txt_password);
        txt_password.setBounds(140, 150, 150, 40);

        jLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel.setForeground(new java.awt.Color(204, 0, 0));
        getContentPane().add(jLabel);
        jLabel.setBounds(140, 120, 190, 20);

        jButton1.setFont(new java.awt.Font("Trebuchet MS", 1, 14)); // NOI18N
        jButton1.setText("Fermer");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(190, 220, 80, 30);

        jButton2.setFont(new java.awt.Font("Trebuchet MS", 1, 14)); // NOI18N
        jButton2.setText("Connection");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2);
        jButton2.setBounds(40, 220, 110, 30);

        txt_username1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        getContentPane().add(txt_username1);
        txt_username1.setBounds(140, 70, 150, 40);

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

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

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
rs = db.querySelectAll("utilisateur", "username ='" + jLabel.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, "Nom de l'utilisateur ou Mot de passe incorrect");
    jLabel.setText("erreur!!!!!");
    jLabel.setVisible(true);
     } else {
        if(hak.equals("directeur")){
            Principale h = new Principale();
            h.setVisible(true);
            this.dispose();
        } else {
            Cahier k = new Cahier();
            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);
            }
        });
    }

1 réponse

choukie12 Messages postés 55 Date d'inscription vendredi 11 mars 2016 Statut Membre Dernière intervention 27 juin 2018 2
19 avril 2016 à 17:02
Hello,

Ton import du Logger est pas bon.

Remplace :

import com.sun.istack.internal.logging.Logger;


par :
import java.util.logging.Logger;



Jérémy
0
christian3wilfried1
20 avril 2016 à 12:48
Merci !!!!!!!!!
0
choukie12 Messages postés 55 Date d'inscription vendredi 11 mars 2016 Statut Membre Dernière intervention 27 juin 2018 2 > christian3wilfried1
20 avril 2016 à 16:37
De préférence j'utilise le Logger de slf4j.
http://www.slf4j.org/apidocs/org/slf4j/Logger.html


Si c'est corrigé, pense à mettre résolu et noter la réponse.

Jérémy.
0
Rejoignez-nous