📄 frame6.java~2~
字号:
package library;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
public class Frame12 extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JLabel jLabel2 = new JLabel();
JPasswordField jPasswordField1 = new JPasswordField();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JPasswordField jPasswordField2 = new JPasswordField();
JPasswordField jPasswordField3 = new JPasswordField();
Connection conn;
public Frame12() {
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String connURL ="jdbc:odbc:library";
String user = "sa";
String pw = "123";
conn=DriverManager.getConnection(connURL,user,pw);
}
catch(Exception e)
{
System.out.println("class no found can not connect to sql server"+e);
}
contentPane = (JPanel) getContentPane();
contentPane.setLayout(xYLayout1);
setSize(new Dimension(200, 260));
setTitle("修改密码");
jLabel1.setText("ID");
jButton1.setText("确定");
jButton1.addActionListener(new Frame12_jButton1_actionAdapter(this));
jLabel2.setText("旧密码");
jTextField1.setToolTipText("");
jLabel3.setText("新密码");
jLabel4.setText("新密码");
contentPane.add(jLabel1, new XYConstraints(22, 10, 55, 27));
contentPane.add(jLabel3, new XYConstraints(8, 99, -1, -1));
contentPane.add(jLabel4, new XYConstraints(9, 150, -1, -1));
contentPane.add(jPasswordField1, new XYConstraints(55, 53, 130, 27));
contentPane.add(jLabel2, new XYConstraints(10, 58, -1, -1));
contentPane.add(jPasswordField3, new XYConstraints(55, 145, 130, 27));
contentPane.add(jTextField1, new XYConstraints(56, 9, 130, 27));
contentPane.add(jPasswordField2, new XYConstraints(55, 93, 130, 27));
contentPane.add(jButton1, new XYConstraints(123, 191, 62, 24));
}
public void jButton1_actionPerformed(ActionEvent e) {
F12();
}
void F12(){
try
{
String str1,str2;
str1=jTextField1.getText();
str2=new String(jPasswordField1.getPassword());
Statement pstmt1 = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql= "select * from reader where ID='"+str1+"' AND 密码 = '"+str2+"' ";
ResultSet rs2 = pstmt1.executeQuery(sql);
if (!rs2.next())
{
JOptionPane.showMessageDialog(this,"帐户或者密码错误","错误",JOptionPane.ERROR_MESSAGE);
}
else{
try{
String str3,str4;
str3=new String(jPasswordField2.getPassword());
str4=new String(jPasswordField3.getPassword());
if(str3.equals("")||str4.equals(""))
{
JOptionPane.showMessageDialog(this,"新密码不能为空","失败",JOptionPane.ERROR_MESSAGE);
}
else
{
if(str3.equals(str4))
{
String str10,str11;
str10=new String(jPasswordField1.getPassword());
str11=new String(jPasswordField2.getPassword());
Statement stmt11 = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq1 = "update reader set 密码 = '"+str11+"' where ID = '"+str1+"'";
stmt11.executeUpdate(sq1);
JOptionPane.showMessageDialog(this,"修改成功","成功",JOptionPane.OK_CANCEL_OPTION);
}
else
{
JOptionPane.showMessageDialog(this, "两次输入的新密码不一致", "失败",JOptionPane.ERROR_MESSAGE);
}
}
}
catch(Exception e)
{
System.err.println(e);
}
}
}
catch(Exception e)
{
System.err.println(e);
}
}
/*void ChangePassword()
{
try
{
String str0,str1,str2;
str0=new String(jPasswordField1.getPassword());
str1=new String(jPasswordField2.getPassword());
//str2=new String(jPasswordField3.getPassword());
Statement stmt1 = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq1 = "update reader set 密码 = '"+str1+"' where ID = '"+str0+"'";
stmt1.executeQuery(sq1);
stmt1.close();
}
catch(Exception e)
{
System.err.println(e);
}
}*/
}
class Frame12_jButton1_actionAdapter implements ActionListener {
private Frame12 adaptee;
Frame12_jButton1_actionAdapter(Frame12 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -