📄 user_manage.java
字号:
package mypackage;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
public class User_Manage extends JFrame {
protected static final Component JDialog = null;
private JPasswordField jTextField3;
private JPasswordField jTextField2;
private JPasswordField jTextField1;
/**
* Launch the application
* @param args
*/
public static void main(String args[]) {
try {
User_Manage frame = new User_Manage();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the frame
*/
public User_Manage() {
super();
setTitle("口令维护");
setBounds(100, 100, 370, 208);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
final JPanel panel = new JPanel();
panel.setLayout(null);
getContentPane().add(panel, BorderLayout.CENTER);
final JLabel label = new JLabel();
label.setFont(new Font("", Font.BOLD, 14));
label.setText("旧密码:");
label.setBounds(46, 34, 60, 15);
panel.add(label);
final JLabel label_1 = new JLabel();
label_1.setFont(new Font("", Font.BOLD, 14));
label_1.setText("新密码:");
label_1.setBounds(46, 70, 60, 15);
panel.add(label_1);
final JLabel label_2 = new JLabel();
label_2.setFont(new Font("", Font.BOLD, 14));
label_2.setText(" 确 认:");
label_2.setBounds(46, 102, 60, 15);
panel.add(label_2);
jTextField1 = new JPasswordField();
jTextField1.setBounds(112, 30, 101, 24);
panel.add(jTextField1);
jTextField2 = new JPasswordField();
jTextField2.setBounds(112, 66, 101, 24);
panel.add(jTextField2);
jTextField3 = new JPasswordField();
jTextField3.setBounds(112, 98, 101, 24);
panel.add(jTextField3);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String textfield1=String.valueOf(jTextField1.getPassword());
String textfield2=String.valueOf(jTextField2.getPassword());
String textfield3=String.valueOf(jTextField3.getPassword());
if(jTextField2.getPassword().length==0)
{
JOptionPane.showMessageDialog(JDialog,"新口令不能为空!请重写!","提示",JOptionPane.INFORMATION_MESSAGE);
return;
}
if(!textfield2.equals(textfield3))
{
JOptionPane.showMessageDialog(JDialog,"新口令和确认口令不一致!请重写","提示",JOptionPane.INFORMATION_MESSAGE);
jTextField2.setText("");
jTextField3.setText("");
return;
}
//查找旧口令
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:Password";
Connection conn=DriverManager.getConnection(url,"","");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from User where Pass='"+textfield1+"'");
System.out.println("数据库查询结束");
if(!rs.next())
{
JOptionPane.showMessageDialog(JDialog,"您输入的旧口令不正确!请重写!","提示",JOptionPane.ERROR_MESSAGE);
}
else//旧口令存在,修改数据库
{
// stmt.executeUpdate("update User SET Pass='"+textfield2+"' WHERE Pass='"+textfield1+"'");
PreparedStatement prepstmt=null;
prepstmt =conn.prepareStatement("update User SET Pass='"+textfield2+"' WHERE Pass='"+textfield1+"'");
prepstmt.executeUpdate();
System.out.println("数据库更新正确!");
rs.close();
stmt.close();
prepstmt.close();
conn.close();
dispose();
}
} catch (ClassNotFoundException e) {
// TODO 自动生成 catch 块
System.out.println("没有找到类驱动!");
e.printStackTrace();
} catch (SQLException e) {
// TODO 自动生成 catch 块
System.out.println("数据库抛出异常!");
e.printStackTrace();
}
}
});
button.setText("确认");
button.setBounds(243, 66, 84, 24);
panel.add(button);
final JButton button_1 = new JButton();
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
dispose();
}
});
button_1.setText("取消");
button_1.setBounds(243, 98, 84, 24);
panel.add(button_1);
//
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -