用java编写的图书管理系统中如何修改用户密码,急
privateStringpwd=null;@OverridepublicvoidactionPerformed(ActionEvente){if(e.getSource...
private String pwd=null;
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==OKbut){
try{Class.forName("com.mysql.jdbc.Driver");
}catch(Exception e1){System.out.println("加载驱动程序失败!");}
try{String URL = "jdbc:mysql://localhost/java5";
String USERNAME = "root";
String PASSWORD = "";
Connection con=DriverManager.getConnection(URL,USERNAME,PASSWORD);
Statement sql=con.createStatement();
String user=usertxt.getText();
String Mima=oldtxt.getText();
ResultSet rst=sql.executeQuery(Mima);
if(rst.next())
{String newMima=newtxt.getText();
//String s="update manager set mpwd='"+newMima+"' from manager where mname='"+user+"'and mpwd='"+Mima+"'";
//String s="update manager set mpwd='"+newMima+"'from manager where mname='root'";
String s= "update manager set mpwd = '"+newMima+"' where mpwd = '"+Mima+"'and mname='"+user+"'";
sql=con.createStatement();
int updateMima=sql.executeUpdate(s);
if(updateMima==1)
{JOptionPane.showMessageDialog(null,"密码修改成功!");}
con.close();
repaint();}
else{JOptionPane.showMessageDialog(null,"该用户不存在","警告!", JOptionPane.YES_NO_OPTION);}
usertxt.setText("");
oldtxt.setText("");
newtxt.setText("");
} catch(Exception e1)
{
System.out.println(""+e1.getMessage());
}
} 展开
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==OKbut){
try{Class.forName("com.mysql.jdbc.Driver");
}catch(Exception e1){System.out.println("加载驱动程序失败!");}
try{String URL = "jdbc:mysql://localhost/java5";
String USERNAME = "root";
String PASSWORD = "";
Connection con=DriverManager.getConnection(URL,USERNAME,PASSWORD);
Statement sql=con.createStatement();
String user=usertxt.getText();
String Mima=oldtxt.getText();
ResultSet rst=sql.executeQuery(Mima);
if(rst.next())
{String newMima=newtxt.getText();
//String s="update manager set mpwd='"+newMima+"' from manager where mname='"+user+"'and mpwd='"+Mima+"'";
//String s="update manager set mpwd='"+newMima+"'from manager where mname='root'";
String s= "update manager set mpwd = '"+newMima+"' where mpwd = '"+Mima+"'and mname='"+user+"'";
sql=con.createStatement();
int updateMima=sql.executeUpdate(s);
if(updateMima==1)
{JOptionPane.showMessageDialog(null,"密码修改成功!");}
con.close();
repaint();}
else{JOptionPane.showMessageDialog(null,"该用户不存在","警告!", JOptionPane.YES_NO_OPTION);}
usertxt.setText("");
oldtxt.setText("");
newtxt.setText("");
} catch(Exception e1)
{
System.out.println(""+e1.getMessage());
}
} 展开
6个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询