adminuserdao.java

来自「一个完整的网络订餐系统」· Java 代码 · 共 85 行

JAVA
85
字号
package com.systemuser.dao;

import java.sql.*;
import java.util.*;
import com.common.*;
import com.util.*;

public class AdminuserDao {

  public AdminuserDao() {
  }

  public boolean logonEsnack(String adminname, String adminpass) {
    DBConnection dbc = null;
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    boolean isTrue = false;
    String strSQL = " SELECT * FROM adminUser  where adminName='" +
        adminname + "' and adminPass='" + adminpass + "'";

    try {
      dbc = new DBConnection();
      conn = dbc.getDBConnection();
      stmt = conn.createStatement();
      rs = stmt.executeQuery(strSQL);
      if (rs.next()) {
        isTrue = true;
      }
    }
    catch (Exception exception) {
      exception.printStackTrace();
    }
    finally {
      try {
        if (rs != null)
          rs.close();
        if (stmt != null)
          stmt.close();
        if (conn != null)
          dbc.closeDBConnection(conn);
      }
      catch (SQLException e) {}
    }
    return isTrue;
  }

 //更新管理员的登录时间
  public int updateLogonDate(String adminname) {
    int nRet = 0;
    DBConnection dbc = null;
    Connection conn = null;
    Statement stmt = null;
    String strSQL = null;

    try {
      dbc = new DBConnection();
      conn = dbc.getDBConnection();
      stmt = conn.createStatement();
      strSQL = "update adminUser set lastLogindate=getdate() "+
          " where adminname='" + adminname + "'";
      nRet = stmt.executeUpdate(strSQL);
    }
    catch (Exception e) {
      nRet = -1;
      e.printStackTrace();
      System.out.println("\n" + e.toString() + "更新管理员的登录时间" + strSQL); /////错误处理!
    }
    finally {
      try {
        if (stmt != null) {
          stmt.close();
        }
        if (conn != null) {
          dbc.closeDBConnection(conn);
        }
      }
      catch (Exception ex) {}
    }
    return nRet;
  }

}

⌨️ 快捷键说明

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