⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 updateframe.java~4~

📁 基于JB的网络数据库系统开发
💻 JAVA~4~
字号:
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.executeUpdate(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 + -