bonjours;
je suis entraine de la réalisation d'une application mais pour la classe de l'authentification
j'ai réalisé le code suivant
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
public class Athentificatin extends JFrame{
public String pseudo;
private String mdpCli;
JButton b1,b2;
JTextField tlogin;
JPasswordField tpwd;
JTextField tloginx;
Vecteur usrs;//=new Vecteur();
User usr;
public String s1=new String();
public Athentificatin(String s,Vecteur utilisateurs){
super(s);
usrs=new Vecteur(utilisateurs);
//getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER,50, 20));
JPanel p=new JPanel(new BorderLayout());
this.setContentPane(p);
JPanel p1=new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel p2=new JPanel(new FlowLayout(FlowLayout.CENTER));
JPanel p3=new JPanel(new GridLayout(3,1));
b1=new JButton("Valider");
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
String login,pwd;
login=tlogin.getText();
pwd=tpwd.getText();
tlogin.setText("");
tpwd.setText("");
// chargement du pilote jdbc:odbc
try{
Class.forName("com.mysql.jdbc.Driver");
//Etablissement de la connexion
Connection con = DriverManager.getConnection("jdbc:mysql:///mabase", "root","");
JOptionPane.showMessageDialog(null, "Connection OK");
// Création d'une instruction
Statement smt = con.createStatement();
// Exécution d'une requete
String tmp;
int flag = 0;
pseudo=tlogin.getText();
String req=("select Password from utilisateur where login like '" + pseudo + "'" );
ResultSet rs = smt.executeQuery(req);
while(rs.next())
{
tmp=rs.toString();
if (tmp.equals(tpwd.getText())) {
JOptionPane.showMessageDialog(null, "authentification valide");
// acc a=new acc();
// a.show();
setVisible(false);
flag = 1;
}
}
if(flag==0){
JOptionPane.showMessageDialog(null, "le mot de passe na pas pu etre valide retenez une authentification");
}
con.close();
}
catch(ClassNotFoundException e1) {
System.err.println(" Erreur de chargement du driver :" + e1) ;
}
catch(SQLException sqle) {
System.err.println(" Erreur lors de la connexion : "+ sqle) ;
}
}
});
p2.add(b1);
JButton b2=new JButton("Annuler");
p2.add(b2);
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
p.add("South",p2);
p3.add(new JLabel("Login:"));
tlogin=new JTextField(10);
p3.add(tlogin);
p3.add(new JLabel("Password:"));
tpwd=new JPasswordField(10);
p3.add(tpwd);
p.add("North",p3);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
dispose();
}
});
}
}
la connection est établie mais lorsque je tape le login et le password ils'affiche
le mot de passe na pas pu etre valide retenez une authentification
s'il vous plait n'hesitez pas de me répondre
et merci a tous