import java.awt.* ; import java.awt.event.*; import java.sql.*; import javax.swing.* ; public class ModifierPass extends JFrame { private JButton modifier ; private JButton annuler; private JPasswordField mot_pass1,mot_pass2,mot_pass3; private JLabel Password1,Password2,Password3,bienvenue,a,b; public ModifierPass () { super() ; Container c = getContentPane(); setTitle("Modifier Mot De Passe") ; setSize(470, 400) ; this.setLocationRelativeTo(null); c.setBackground(Color.getHSBColor(0.56f, 1.0f, 0.9f)); JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JPanel p3 = new JPanel(); JPanel p4 = new JPanel(); JPanel p5 = new JPanel(); JPanel p6 = new JPanel(new GridLayout(4,1)); p3.setBackground(Color.getHSBColor(0.56f, 1.0f, 0.9f)); p1.setBackground(Color.getHSBColor(0.56f, 1.0f, 0.9f)); p2.setBackground(Color.getHSBColor(0.56f, 1.0f, 0.9f)); p4.setBackground(Color.getHSBColor(0.56f, 1.0f, 0.9f)); p5.setBackground(Color.getHSBColor(0.56f, 1.0f, 0.9f)); bienvenue = new JLabel (" Saisissez un nouveau mot de passe"); mot_pass1 = new JPasswordField(10) ; Password1 = new JLabel("Mot de passe actuel:"); mot_pass2 = new JPasswordField(10) ; Password2 = new JLabel("Nouveau mot de passe:"); mot_pass3 = new JPasswordField(10) ; Password3 = new JLabel("Confirmer mot de passe:"); modifier = new JButton(new ImageIcon("C:/Users/DELL/workspace/base/modifier.png")); modifier.setText("Modifier"); annuler = new JButton(new ImageIcon("C:/Users/DELL/workspace/base/annuler.png")); annuler.setText("Annuler"); modifier.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { try { actionstart(e); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); annuler.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { menuItemActionPerformed(e); } }); p1.add(Password1); p1.add(mot_pass1); p2.add(Password2); p2.add(mot_pass2); p3.add(Password3); p3.add(mot_pass3); p4.add(modifier); p4.add(annuler); AfficheImage sigle = new AfficheImage("C:/Users/DELL/workspace/base/tunisie-telecom-.jpg"); c.setLayout(new GridLayout(3,1)); c.add(sigle); p5.add(bienvenue,"center"); p6.add(p5); p6.add(p1); p6.add(p2); p6.add(p3); c.add(p6); c.add(p4); } private void menuItemActionPerformed(ActionEvent e) { directeur fen = new directeur(); this.setVisible(false); fen.setVisible(true); } class AfficheImage extends JPanel { Image eau; AfficheImage(String s) { eau = getToolkit().getImage(s); } public void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(eau, 0, 0, getWidth(), getHeight(), this); } } private String actionstart(MouseEvent e) throws SQLException{ administrateur fen3 = new administrateur(); directeur fen2 = new directeur(); autre fen1 = new autre(); // this.setVisible(false) ; if((verifier().equals("oui"))){ String mdp1 = mot_pass1.getText(); String mdp2 = mot_pass2.getText(); String mdp3 = mot_pass3.getText(); if (mdp2.equals(mdp3)) { ResultSet rs; String url = "C:/Users/DELL/workspace/base/admin.mdb"; try { ConnextionAcc con = new ConnextionAcc (url,"Admin",""); rs con.SQLSelect("UPDATE authentification SET mot_de_passe '"+mdp2+"' WHERE mot_de_passe = '"+mdp1+"';" ); while(rs.next()) { java.sql.Statement stmt = con.createStatement(); stmt.close(); } } catch(NullPointerException e1){ return("e1"); } JOptionPane.showMessageDialog(fen2, "Mot de passe modifié") ; this.setVisible(false); fen2.setVisible(true); } else if (!(mdp2.equals(mdp3))) { JOptionPane.showMessageDialog(fen3, "verifier") ; this.setVisible(true); } } else if((verifier().equals("non"))){ JOptionPane.showMessageDialog(fen3, "verifier votre identifiant et votre mot de passe") ; this.setVisible(true); } return null; } public String verifier() { ResultSet rs; String url = "C:/Users/DELL/workspace/base/admin.mdb"; try { ConnextionAcc con = new ConnextionAcc (url,"Admin",""); rs = con.SQLSelect("Select * from authentification"); while(rs.next()) { String s = rs.getString(2); String mdp = mot_pass1.getText(); if( mdp.equals(s)) { return("oui"); } } return("non"); } catch(NullPointerException e2){ return("e2"); } catch(SQLException e1){ return("e1"); } } public static void main(String[] args) { JFrame fen = new ModifierPass() ; fen.setVisible(true) ; Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - fen.getWidth()) / 2); int y = (int) ((dimension.getHeight() - fen.getHeight()) / 2); fen.setLocation(x, y); } }
import java.sql.*; public class ConnextionAcc { // Chemin de la base private String path; // Nom d'utilisateur private String user; // Mot de passe private String password; // Connection vers la base private Connection connection; /* Constructeur */ public ConnextionAcc(String path, String user, String password) { this.path = path; this.user = user; this.password = password; if(this.connect()==false) System.out.println("Problème de connexion!"); } /*; * Connection à la base * @return : true si la connexion est réussite, false si échouillée */ public boolean connect() { try { // Chargement du driver ODBC Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Connexion à la base String connectionString = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" + path; connection = DriverManager.getConnection(connectionString, user, password); } catch (ClassNotFoundException e) { System.out.println("Problème avec le driver ODBC"); return false; } catch (SQLException e) { System.out.println("Impossible de se connecter à la base"); return false; } return true; } /* * Déconnexion de la base * @return : true si la déconnexion est réussite, false sinon */ public boolean disconnect() { try { connection.close(); return true; } catch (SQLException e) { return false; } } /* * Envoi d'une requête de séletion * @param : sql * @return : result */ public ResultSet SQLSelect(String sql) throws SQLException { Statement statement = null; ResultSet result = null; try { statement = connection.createStatement(); result = statement.executeQuery(sql); return result; } catch (SQLException e) { result.close(); statement.close(); System.out.println(e.toString()); return null; } } /* * Envoi d'une requête de mise à jour (insert, update, delete) * @param : sql */ public int SQLUpdate(String sql) throws SQLException { Statement statement = null; int j=0; try { statement = connection.createStatement(); j=statement.executeUpdate(sql); } catch (SQLException e) { statement.close(); } return(j); } public Statement createStatement() { // TODO Auto-generated method stub return null; } }
import java.awt.* ; import java.awt.event.*; import java.sql.*; import javax.swing.* ; public class ModifierPass extends JFrame { private JButton modifier ; private JButton annuler; private JPasswordField mot_pass1,mot_pass2,mot_pass3; private JLabel Password1,Password2,Password3,bienvenue,a,b; public ModifierPass () { super() ; Container c = getContentPane(); setTitle("Modifier Mot De Passe") ; setSize(470, 400) ; this.setLocationRelativeTo(null); c.setBackground(Color.getHSBColor(0.56f, 1.0f, 0.9f)); JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JPanel p3 = new JPanel(); JPanel p4 = new JPanel(); JPanel p5 = new JPanel(); JPanel p6 = new JPanel(new GridLayout(4,1)); p3.setBackground(Color.getHSBColor(0.56f, 1.0f, 0.9f)); p1.setBackground(Color.getHSBColor(0.56f, 1.0f, 0.9f)); p2.setBackground(Color.getHSBColor(0.56f, 1.0f, 0.9f)); p4.setBackground(Color.getHSBColor(0.56f, 1.0f, 0.9f)); p5.setBackground(Color.getHSBColor(0.56f, 1.0f, 0.9f)); bienvenue = new JLabel (" Saisissez un nouveau mot de passe"); mot_pass1 = new JPasswordField(10) ; Password1 = new JLabel("Mot de passe actuel:"); mot_pass2 = new JPasswordField(10) ; Password2 = new JLabel("Nouveau mot de passe:"); mot_pass3 = new JPasswordField(10) ; Password3 = new JLabel("Confirmer mot de passe:"); modifier = new JButton(); modifier.setText("Modifier"); annuler = new JButton(); annuler.setText("Annuler"); modifier.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { try { actionstart(e); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); annuler.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { menuItemActionPerformed(e); } }); p1.add(Password1); p1.add(mot_pass1); p2.add(Password2); p2.add(mot_pass2); p3.add(Password3); p3.add(mot_pass3); p4.add(modifier); p4.add(annuler); c.setLayout(new GridLayout(2,1)); p5.add(bienvenue,"center"); p6.add(p5); p6.add(p1); p6.add(p2); p6.add(p3); c.add(p6); c.add(p4); } private void menuItemActionPerformed(ActionEvent e) { this.setVisible(false); } private String actionstart(MouseEvent e) throws SQLException{ administrateur fen3 = new administrateur(); directeur fen2 = new directeur(); autre fen1 = new autre(); // this.setVisible(false) ; String mdp1 = mot_pass1.getText(); String mdp2 = mot_pass2.getText(); String mdp3 = mot_pass3.getText(); if (mdp2.equals(mdp3)) { String url = "C:/Users/DELL/workspace/base/admin.mdb"; try { ConnextionAcc con = new ConnextionAcc (url,"Admin",""); String req="UPDATE authentification SET mot de passe = '"+mdp2+"' WHERE mot de passe = '"+mdp1+"' ; " ; java.sql.Statement stmt = con.createStatement(); stmt.executeUpdate(req); stmt.close(); } catch(NullPointerException e1){ return("e1"); } JOptionPane.showMessageDialog(fen2, "Mot de passe modifié") ; this.setVisible(false); fen2.setVisible(true); } else if (!(mdp2.equals(mdp3))) { JOptionPane.showMessageDialog(fen3, "verifier") ; this.setVisible(true); } return null; } public static void main(String[] args) { JFrame fen = new ModifierPass() ; fen.setVisible(true) ; Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - fen.getWidth()) / 2); int y = (int) ((dimension.getHeight() - fen.getHeight()) / 2); fen.setLocation(x, y); } } }
try { ConnextionAcc con = new ConnextionAcc (url,"Admin",""); String req="UPDATE authentification SET mot de passe = '"+mdp2+"' WHERE mot de passe = '"+mdp1+"' ; " ; java.sql.Statement stmt = con.createStatement(); stmt.executeUpdate(req); stmt.close(); } catch(NullPointerException e1){ return("e1"); }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionprivate String actionstart(MouseEvent e) throws SQLException{ String mdp1 = mot_pass1.getText(); String mdp2 = mot_pass2.getText(); String mdp3 = mot_pass3.getText(); String url = "C:/Users/DELL/workspace/base/admin.mdb"; try { ConnextionAcc con = new ConnextionAcc (url,"Admin",""); String req="UPDATE authentification SET 'mot_de_passe' = '"+mdp2+"' WHERE 'mot_de_passe' = '"+mdp1+"'" ; java.sql.Statement stmt = con.createStatement(); stmt.executeUpdate(req); stmt.close(); } catch(NullPointerException e1){ return("e1"); } return url; }