operatormodel.java

来自「一个资产管理系统的源码」· Java 代码 · 共 83 行

JAVA
83
字号
/**
 *OperatorModel.java:建立操作员实体类。
 *包括:与数据库进行改、查操作。
 */

package zichan;

import java.sql.*;
import java.math.*;

public class OperatorModel {
   String name;
   String pwd;
   DBConnt dbc;
   Connection conn;
   public OperatorModel() {
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
   public OperatorModel(String n,String e) {
        name = n;
        pwd = e;
   }
   public void setAll(String e,String p) {
        name = e;
        pwd = p;
   }
   public String getName() {
        return name;
   }
   private String getPwd() {
        return pwd;
   }

   public int verify() {
      dbc = new DBConnt();
      conn = dbc.getConnection();
      int cnt=0;
      String sql;
      String sql = "SELECT count(*) FROM operator where name = '"+this.name+"' and pwd = '"+this.pwd+"'";
      try {
      Statement stmt = conn.createStatement();
      ResultSet rset = stmt.executeQuery (sql);
      while (rset.next()) {
        cnt = rset.getInt(1);
      }
      conn.commit();
      rset.close();
      stmt.close();
      conn.close();
      }
      catch (java.sql.SQLException s) {
        System.out.println("exception: " + s.getMessage());
      }
      return cnt;
    }

    public void update() {
      dbc = new DBConnt();
      conn = dbc.getConnection();
      try {
      PreparedStatement pstmt =
      conn.prepareStatement("update OPERATOR set PWD = ? where name = ?");
      pstmt.setString(1, pwd);
      pstmt.setString(2, name);
      pstmt.execute();
      conn.commit();
      conn.close();
      }
      catch (java.sql.SQLException s) {
        System.out.println("exception: " + s.getMessage());
      }
   }

    private void jbInit() throws Exception {
    }
}


⌨️ 快捷键说明

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