Programmation java

Résolu
karamel0510 Messages postés 6 Date d'inscription mardi 7 avril 2009 Statut Membre Dernière intervention 18 mai 2009 - 18 mai 2009 à 12:41
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 - 18 mai 2009 à 16:46
bon jour j'ai un probleme dans l'authentification d'un utilisateur par exemple "infermier" il doit taper son login et mot de passe et puis cliquer sur valider
pour aller a son compte qui de meme contient des boutons "ajouter patient" et "modifier patient"  et moi j'ai cree une base de donnee access et j'ai rempli manuellement les tables infermier, medecin et patient,j'ai fais une connection entre java et access dans le "Action performed "de bouton "valider"  de la fenetre de l'authentification infermier mais ca ne marche pas de tout.donc je peut pas acceder a la fenetre compte infermier . et voila le code de la fenetre authentification infermier, s;il vouc plais aidez moi et merci d'avance
je travaille avec Netbeans 6.5 et merci
avec remarque la connection s'etablie mais
les deux messages dans le catch s'affichent: probleme de lecture de la requette et erreurrrr utilisateur.   merci bien

import java.beans.Statement;
import java.sql.*;
import javax.swing.JButton;
import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * autehentification_inf.java
 *
 * Created on 17-May-2009, 14:11:50
 */

/**
 *
 * @author amouna
 */
public class autehentification_inf extends javax.swing.JFrame {

    /** Creates new form autehentification_inf */
    public autehentification_inf() {
        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() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jPasswordField1 = new javax.swing.JPasswordField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Algerian", 3, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(120, 120, 255));
        jLabel1.setText("AUTHENTIFICATION INFERMIER");

        jLabel2.setFont(new java.awt.Font("Californian FB", 1, 14)); // NOI18N
        jLabel2.setText("Login :");

        jLabel3.setFont(new java.awt.Font("Californian FB", 1, 14)); // NOI18N
        jLabel3.setText("Password");

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icone/arrow_turn_left.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Valider");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 399, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 489, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(81, 81, 81)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2))
                        .addGap(80, 80, 80)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPasswordField1)
                            .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(154, 154, 154)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(96, 96, 96)
                        .addComponent(jButton2)))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(43, 43, 43)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(43, 43, 43)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 59, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2)
                    .addComponent(jButton1))
                .addGap(31, 31, 31))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

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

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        JButton ss=(JButton)evt.getSource();
        if(ss==jButton1)
          {  principale prin=new principale();

             prin.setVisible(true); }
    }                                       
        Connection connect=null;
        Statement S=null,S1=null;
        ResultSet RS=null,RS1=null;
        String select,login1,motpass;
        int nbcolonnes;
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
          login1=    jTextField1.getText();
           motpass= jPasswordField1.getText();

        JButton s=(JButton)evt.getSource();

        if(s==jButton2)
    {

        try
        {

            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            connect=DriverManager.getConnection("jdbc:odbc:access2007");
            System.out.println("connexion avec la base est etablie");
        }
         catch(Exception e1)
         {
                System.out.println("connection non etablie");
         }
        // requette select
        try{
            S=connect.createStatement();

            RS=S.executeQuery("select login,password from identi_mede  where login= '"+login1+"' and password='"+motpass+"'");
            System.out.println("la requette est lue");
            }
            catch(Exception e3)
            {
                System.out.println("probleme de lecture de la requette");
            }
        try
        {

            if(RS.next()==true)
            {
                 infirmier infire=new infirmier();

                   infire.setVisible(true);
            }

            else
                {

         JOptionPane.showMessageDialog(null,"Fausse Authentification"," Attention ",JOptionPane.INFORMATION_MESSAGE);
         jTextField1.setText(" ");
         jPasswordField1.setText("");
                }

        }
        catch(Exception e3)
        {
            System.out.println("erreurrrr utilisateur");
        }
    }

    }                                       

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new autehentification_inf().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.JPanel jPanel1;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration                  

}

4 réponses

cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
18 mai 2009 à 14:12
Salut,

Si au lieu d'afficher un message bidon dans tes exceptions, tu affichais la véritable erreur, ca pourrait aider à savoir d'où vient ton problème...

au lieu de : System.out.println("probleme de lecture de la requette"); fais plutôt : e3.printStackTrace();
3
lordfatsoe Messages postés 2 Date d'inscription mercredi 1 avril 2009 Statut Membre Dernière intervention 18 mai 2009
18 mai 2009 à 14:34
ou aussi fait e.getmessage()
3
karamel0510 Messages postés 6 Date d'inscription mardi 7 avril 2009 Statut Membre Dernière intervention 18 mai 2009
18 mai 2009 à 16:11
Merci pour votre remarques constructives
mais vraiment est ce que vous pouvez m'expliquer pourquoi la raquette n'est pas
transmis? et merci
0
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
18 mai 2009 à 16:46
Comme je te le disais : sans la stacktrace, et donc, sans savoir qu'est-ce qui est à l'orgine de l'erreur, c'est impossible à te répondre !

C'est le problème d'afficher des messages bateaux à l'écran : ca n'apporte rien d'utilise, que ce soit à l'utilisateur final comme au développeur...
0
Rejoignez-nous