📄 modifyuse.java
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;
class ModifyUse 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 ModifyUse(){
cp.setBackground(Color.magenta);
bt1.setBackground(Color.red);
bt2.setBackground(Color.red);
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:student";
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(Exception e){System.out.println("加载驱动失败");}
ModifyUse df=new ModifyUse();
}
public void actionPerformed(ActionEvent e){
if (e.getSource()==bt2){f.setVisible(false);}
if (e.getSource()==bt1){
try{
Connection con=DriverManager.getConnection("jdbc:odbc:student");
Statement s=con.createStatement();
String str="select * from user1 where ID='"+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:student");
String str1="UPDATE user1 set Password='"+T3.getText()+"' where ID='"+T1.getText()+"'";
PreparedStatement ps=con.prepareStatement(str1);
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,"密码输入错误,或用户不存在!");
T2.setText(null);
T3.setText(null);
T3.setText(null);
T4.setText(null);}
}
catch(Exception ee)
{System.out.println("错误信息:"+ee.getMessage());}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -