?? updateframe.java~3~
字號:
package simpleusers;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class UpdateFrame extends JFrame { Connection con = null; Statement stmt = null; ResultSet rs = null; JButton jButton2 = new JButton(); JLabel jLabel2 = new JLabel(); JButton jButton1 = new JButton(); JLabel jLabel1 = new JLabel(); JPasswordField jP1 = new JPasswordField(); JTextField jT1 = new JTextField(); JLabel jLabel3 = new JLabel(); JPasswordField jP2 = new JPasswordField(); public UpdateFrame() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { jT1.setBounds(new Rectangle(137, 46, 131, 37)); jT1.setText(""); jT1.setFont(new java.awt.Font("Dialog", 0, 16)); jP1.setBounds(new Rectangle(137, 102, 131, 37)); jP1.setText(""); jLabel1.setBounds(new Rectangle(63, 46, 61, 30)); jLabel1.setText("用戶名"); jLabel1.setFont(new java.awt.Font("Dialog", 0, 16)); jButton1.setText("確定"); jButton1.addActionListener(new UpdateFrame_jButton1_actionAdapter(this)); jButton1.setFont(new java.awt.Font("Dialog", 0, 14)); jButton1.setBounds(new Rectangle(69, 223, 69, 39)); jLabel2.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel2.setText("舊密碼"); jLabel2.setBounds(new Rectangle(63, 102, 61, 30)); jButton2.setBounds(new Rectangle(184, 223, 69, 39)); jButton2.setFont(new java.awt.Font("Dialog", 0, 14)); jButton2.setText("重置"); this.getContentPane().setLayout(null); jLabel3.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel3.setText("舊密碼"); jLabel3.setBounds(new Rectangle(63, 163, 61, 30)); jP2.setBounds(new Rectangle(137, 157, 131, 37)); jP2.setText(""); this.getContentPane().add(jLabel2, null); this.getContentPane().add(jLabel1, null); this.getContentPane().add(jP1, null); this.getContentPane().add(jT1, null); this.getContentPane().add(jButton1, null); this.getContentPane().add(jButton2, null); this.getContentPane().add(jP2, null); this.getContentPane().add(jLabel3, null); } void jButton1_actionPerformed(ActionEvent e) { String username=jT1.getText().trim(); String oldpwd=jP1.getText().trim(); String newpwd=jP2.getText().trim(); String sql1="select * from userandpwd where username='"+username+ "' and pwd='"+oldpwd+"'"; String sql2="update userandpwd set pwd='"+newpwd+"' where username="+ "'"+username+"'"; String msg=null; try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); }catch(ClassNotFoundException e1){ System.out.println("加載JDBC數據庫驅動程序出錯"); } String url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=Test"; try{ con = DriverManager.getConnection(url, "sa", ""); stmt = con.createStatement(); rs = stmt.executeQuery(sql1); }catch(SQLException e2){ System.out.println("數據庫連接出錯"); } try{ if (rs.next()){ stmt.executeQuery(sql2); msg="歡迎你修改密碼!\n"+ "你修改密碼的用戶名稱為"+username+ ".\n新的密碼為"+newpwd+"."; }else msg="對不起,你輸入的用戶名或密碼不正確!"; }catch(SQLException e3 ){ System.out.println("讀取數據出錯"); } try{ rs.close(); stmt.close(); con.close(); }catch(SQLException e4){ System.out.println("關閉對象連接出錯"); } MessageFrame m1=new MessageFrame(msg); m1.setSize(340,280); this.dispose(); m1.show(); }}class UpdateFrame_jButton1_actionAdapter implements java.awt.event.ActionListener { UpdateFrame adaptee; UpdateFrame_jButton1_actionAdapter(UpdateFrame adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -