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

📄 userid.java~97~

📁 基于Java的物流管理系统的开发与应用
💻 JAVA~97~
字号:
package untitled5;

import java.io.*;
import java.net.*;
import java.sql.*;
import java.lang.*;
import javax.sql.*;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class userid
    extends Applet {

  XYLayout xYLayout1 = new XYLayout();
  JLabel jLabel1 = new JLabel();
  JTextField jTextField1 = new JTextField();
  JLabel jLabel2 = new JLabel();
  JTextField jTextField2 = new JTextField();
  JButton jButton1 = new JButton();

  //Initialize the applet
  public void init() {
    jLabel1.setText("姓名");
    this.setLayout(xYLayout1);
    jTextField1.setText("");
    jLabel2.setText("密码");
    jButton1.setText("登录");
    jButton1.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        System.out.println("ok");
        validID();
      }
    });
    Font font = new Font("宋体", Font.PLAIN, 12);
    add(jLabel1, new XYConstraints(13, 94, -1, 22));
    add(jTextField1, new XYConstraints(34, 94, 78, 25));
    add(jLabel2, new XYConstraints(114, 94, -1, 22));
    add(jTextField2, new XYConstraints(137, 94, 73, 25));
    add(jButton1, new XYConstraints(209, 94, -1, 26));
  }

  void validID() {
    try {
      String str1, str2;
      str1 = jTextField1.getText();
      str2 = jTextField2.getText();
     // System.out.println(str1);
      //System.out.println(str2);
      //装载jdbc驱动程序
      String driverName = "oracle.jdbc.OracleDriver";
      Driver driver = (Driver) Class.forName(driverName).newInstance();

      //连接数据库
      Connection con = DriverManager.getConnection(
          "jdbc:oracle:thin:@thsspc0791:1521:tongfang", "sa", "tongfang");
      /*   Statement stmt=con.createStatement();
        ResultSet rest=stmt.executeQuery(" select name from first");
       while(rest.next())
        System.out.println(rest.getString(1)); */

      PreparedStatement pstmt = con.prepareStatement(
          " select name ,id,password from first where name=?");
      pstmt.setString(1, str1);
      ResultSet res = pstmt.executeQuery();
      //String sa=res.getString(1);
      if ((!res.next()) || res.getString("id") == null) {
        JOptionPane.showMessageDialog(this, "查无此人", "错误",
                                      JOptionPane.ERROR_MESSAGE);
      }else {
        if ( !res.getString("ID").equals(str2)) {
          System.out.println("ninhao");
        }else {
          System.out.println("aksdjflkajsdlf");
          do{
            System.out.println(res.getString(1)+":" + res.getLong(2) + ":" +res.getLong(3));
          }while (res.next());
          loader();
        }
      }
      pstmt.close();
      con.close();

    }catch (InstantiationException e) {
      System.out.println(e.getMessage());
    }catch (IllegalAccessException e) {
      System.out.println(e.getMessage());
    }catch (ClassNotFoundException e) {
      System.out.println(e.getMessage());
    }catch (SQLException edd) {
      edd.printStackTrace() ;
      System.out.println(edd.getMessage());
    }
  }

  void loader() {
    try {
     Frame1   Frame= new Frame1();
       Frame.show();

    }
    catch (Exception ew) {

          System.out.println(ew.getMessage());
    }

  }

  class ValidFailedException
      extends SQLException {
    public ValidFailedException() {
    }

    public ValidFailedException(String reason) {
      super(reason);
    }
  }

}

⌨️ 快捷键说明

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