📄 modifyuser.java.bak
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;
class ModifyUser extends JFrame implements ActionListener
{
JFrame f=new JFrame("修改密码");
JLabel lb1=new JLabel("用户名:",Label.LEFT);
JLabel lb2=new JLabel("原始密码:",Label.LEFT);
JLabel lb3=new JLabel("新密码:",Label.LEFT);
JLabel lb4=new JLabel("确认新密码:",Label.LEFT);
JButton bt1=new JButton("确定");
JButton bt2=new JButton("取消");
JTextField T1 = new JTextField(15);
JPasswordField T2 = new JPasswordField(15);
JPasswordField T3= new JPasswordField(15);
JPasswordField T4= new JPasswordField(15);
Container cp=f.getContentPane();
public ModifyUser(){
cp.setBackground(Color.pink);
bt1.setBackground(Color.orange);
bt2.setBackground(Color.orange);
cp.setLayout(null);
cp.add(lb1);lb1.setBounds(40,20,100,30);
cp.add(T1);T1.setBounds(160,20,100,30);
cp.add(lb2);lb2.setBounds(40,60,100,30);
cp.add(T2);T2.setBounds(160,60,100,30);
cp.add(lb3);lb3.setBounds(40,100,100,30);
cp.add(T3);T3.setBounds(160,100,100,30);
cp.add(lb4);lb4.setBounds(40,140,100,30);
cp.add(T4);T4.setBounds(160,140,100,30);
cp.add(bt1);bt1.setBounds(80,190,80,30);
cp.add(bt2);bt2.setBounds(180,190,80,30);
bt1.addActionListener(this);
bt2.addActionListener(this);
f.setBounds(400,300,350,300);
f.setVisible(true);
}
public static void main(String[] args)
{
String JDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String conURL="jdbc:odbc:Xsstudent";
try{Class.forName(JDriver);}
catch(Exception e){System.out.println("加载驱动失败");}
ModifyUser df=new ModifyUser();
}
public void actionPerformed(ActionEvent e){
if (e.getSource()==bt2){f.setVisible(false);}
if (e.getSource()==bt1)
{ if(T1.getText().equals("")||T2.getText().equals("")||T3.getText().equals("")||T4.getText().equals(""))
{ JOptionPane.showMessageDialog(this,"抱歉,您还有信息没有填写,请确认并重新填写");}
else{
try{
Connection con=DriverManager.getConnection("jdbc:odbc:Xsstudent");
Statement s=con.createStatement();
String str="select * from user where userid='"+T1.getText()+"'and password='"+T2.getText()+"'";
ResultSet rs=s.executeQuery(str);
boolean isexit=false;
try{isexit=rs.next();}
catch(Exception ee){}
if(isexit)
{
if(T3.getText().equals(T4.getText()))
{
try{
Connection con1=DriverManager.getConnection("jdbc:odbc:Xsstudent");
String str1="UPDATE user set password='"+T3.getText()+"' where id=?";
PreparedStatement ps=con.prepareStatement(str1);
ps.setString(1,T1.getText().trim());
ps.executeUpdate();
T1.setText(null);
T2.setText(null);
T3.setText(null);
T4.setText(null);
JOptionPane.showMessageDialog(this,"密码修改成功!");
ps.close();
}catch(Exception ee)
{System.out.println("修改错误信息:"+ee.getMessage());}
}
else
{JOptionPane.showMessageDialog(this,"两次输入密码不一致,请重新输入!");
T3.setText(null);
T4.setText(null);}
}
else{
JOptionPane.showMessageDialog(this,"密码输入错误,或用户不存在!");
T1.setText(null);
T2.setText(null);
T3.setText(null);
T4.setText(null);
}
}
catch(Exception ee)
{System.out.println("错误信息error:"+ee.getMessage());}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -