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

📄 passwordsquery.java

📁 学生信息管理系统,包括成绩查询,成绩排序,用ACCESS做数据库连接
💻 JAVA
字号:
package Chapter1;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.awt.Rectangle;
import java.awt.Font;

public class  PasswordsQuery extends JFrame implements ActionListener
{
   public static final int WIDTH=400;
   public static final int HEIGHT=400;
  JLabel jLabel1 = new JLabel();
  JTextField jTextField1 = new JTextField();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JButton jButton3 = new JButton();
  JComboBox jComboBox1 = new JComboBox();
  JLabel jLabel2 = new JLabel();
  public PasswordsQuery()
   {
     setSize(WIDTH,HEIGHT);
     setTitle("查询密码");
     Container contentPane=getContentPane();
     contentPane.setBackground(Color.green);
    try
    {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
   }
   public void actionPerformed(ActionEvent e)
   {
     if(e.getActionCommand().equals("查询"))
        { //用于获取用户输入的信息
           try
           { String password="";
             String url="jdbc:odbc:MySecondAccess";
             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             Connection con=DriverManager.getConnection(url,"","");
             Statement stmt=con.createStatement();
             String  SQLOrder1="SELECT * FROM ManagersInformation  WHERE 帐号='"+jTextField1.getText()+"' ";
             String  SQLOrder2="SELECT * FROM StudentsInformation  WHERE 帐号='"+jTextField1.getText()+"' ";
             ResultSet resultSet=null;
               if(jComboBox1.getSelectedIndex()==0)
                        resultSet= stmt.executeQuery(SQLOrder1);
               else if(jComboBox1.getSelectedIndex()==1)
                        resultSet= stmt.executeQuery(SQLOrder2);
            if(resultSet.next())
            {
                 password=resultSet.getString(3);
                 JOptionPane.showMessageDialog(null,"密码是"+password,"提示信息",JOptionPane.INFORMATION_MESSAGE);
            }
            else
              JOptionPane.showMessageDialog(null,"对不起,不存在此帐号!","张呈刚提醒您.......",JOptionPane.WARNING_MESSAGE);
             stmt.close();
             con.close();
             jTextField1.setText("");
           }
           catch(Exception ex)
           {
             System.out.println("Failure in connecting with the database!");
             System.out.println(ex.getMessage());
           }
        }
      else if (e.getActionCommand().equals("重置"))
      {
          jTextField1.setText("");
      }
      else if  (e.getActionCommand().equals("返回"))
      {
           this.dispose();
           ManagerInterface n1= new ManagerInterface();
           StudentInterface n2=new  StudentInterface();
           if(Login.jComboBox1.getSelectedIndex()==0)
                 {  n1.setVisible(true);  n2.dispose();}
           else if(Login.jComboBox1.getSelectedIndex()==1)
                 {  n2.setVisible(true);  n1.dispose(); }
      }
   }
   public static void main(String[] args)
   {
       PasswordsQuery n=new PasswordsQuery();
       n.setVisible(true);
   }
  private void jbInit() throws Exception {
    jLabel1.setFont(new java.awt.Font("Dialog", 1, 13));
    jLabel1.setText("请输入帐号:");
    jLabel1.setBounds(new Rectangle(61, 135, 106, 26));
    this.setLocale(java.util.Locale.getDefault());
    this.getContentPane().setLayout(null);
    jTextField1.setText("");
    jTextField1.setBounds(new Rectangle(169, 135, 90, 22));
    jButton1.setBounds(new Rectangle(42, 237, 70, 30));
    jButton1.setFont(new java.awt.Font("Dialog", 1, 13));
    jButton1.setText("查询");
    jButton2.setBounds(new Rectangle(162, 236, 70, 30));
    jButton2.setFont(new java.awt.Font("Dialog", 1, 13));
    jButton2.setText("重置");
    jButton3.setBounds(new Rectangle(278, 236, 70, 30));
    jButton3.setFont(new java.awt.Font("Dialog", 1, 13));
    jButton3.setText("返回");
    jComboBox1.setBounds(new Rectangle(170, 50, 88, 23));
    jLabel2.setFont(new java.awt.Font("Dialog", Font.BOLD, 13));
    jLabel2.setText("用户类型:");
    jLabel2.setBounds(new Rectangle(74, 48, 71, 24));
    jComboBox1.addItem("管理员");
    jComboBox1.addItem("学生");
    this.getContentPane().add(jButton1, null);
    this.getContentPane().add(jButton2, null);
    this.getContentPane().add(jButton3, null);
    this.getContentPane().add(jLabel1, null);
    this.getContentPane().add(jTextField1, null);
    this.getContentPane().add(jComboBox1);
    this.getContentPane().add(jLabel2);
    jButton1.addActionListener(this);
    jButton2.addActionListener(this);
    jButton3.addActionListener(this);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -