我已经让代码更改了密码,但它无法正常工作。此代码意味着不使用MySQL表中的Java更改用户密码。
private void btn_ModifierUserActionPerformed(java.awt.event.ActionEvent evt) {
try {
String uname = txt_userName.getText();
String upassword = txt_userPassword.getText();
String newassword = txt_usernewrPassword.getText();
String conNewpassword = txt_userconfirmerPassword.getText();
String grade = jCom_userGrade.getSelectedItem().toString();
byte[] img=null;`
String sql = "SELECT * FROM users where ID='"+txt_userID.getText()+"'";
pst=(PreparedStatement)conn.prepareStatement(sql);
rs=pst.executeQuery();
String passwd = rs.getString("password");
if(rs.next()){
if(!uname.equals("")){
if ( upassword.equals(passwd)) {
//JOptionPane.showMessageDialog(null, usrname);
if (newassword.equals(conNewpassword)) {
if( !newassword.equals("") && !conNewpassword.equals("")){
String sqlup="UPDATE users SET userName='"+uname+"',password='"+newassword+"',Grade='"+grade+"',image='"+img+"' where ID'"+txt_userID.getText()+"'";
pst=(PreparedStatement) conn.prepareStatement(sqlup);
pst.execute();
JOptionPane.showMessageDialog(null, "mise à jour réussie");
}else{
JOptionPane.showMessageDialog(null, "S'IL VOUS PLAÎT ENTRER LES INFORMATIONS");
}
} else {
JOptionPane.showMessageDialog(null, "S'IL VOUS PLAÎT CONFIRMER MOT DE PASSE");
}
}else{
JOptionPane.showMessageDialog(null, "S'IL VOUS PLAÎT ENTRER LE MOT DE PASSE");
}
}else{
JOptionPane.showMessageDialog(null, "S'IL VOUS PLAÎT ENTRER LE NOM D'UTILISATEUR");
}
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
答案 0 :(得分:2)