examineedao.java

来自「基于struts框架的在线考试系统」· Java 代码 · 共 847 行 · 第 1/3 页

JAVA
847
字号
      conditionStr += ("&sex=" + sex);
    }

    if (organization_id == null || "".equals(organization_id)) {
      organization_id = "%";
    } else if (! ("%".equals(organization_id))) {
      conditionStr += ("&organization_id=" + organization_id);
    }

    if (post_index == null || "".equals(post_index)) {
      post_index = "%";
    } else if (! ("%".equals(post_index))) {
      conditionStr += ("&post_index=" + post_index);
    }

    if (state == null || "".equals(state)) {
      state = "%";
    } else if (! ("%".equals(state))) {
      conditionStr += ("&state=" + state);
    }

    if (operation == null || "".equals(operation)) {
      operation = "%";
    } else if (! ("%".equals(operation))) {
      conditionStr += ("&operation=" + operation);
    }


    try {
      if ("%".equals(post_index)) {
        pstmt = conn.prepareStatement(GET_SHARCH_RESULT_WITHOUT_PAGE,
                                      ResultSet.TYPE_SCROLL_SENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
        pstmt.setString(1, examinee_id);
        pstmt.setString(2, name);
        pstmt.setString(3, sex);
        pstmt.setString(4, organization_id);
        pstmt.setString(5, state);
        pstmt.setString(6, operation);
      } else {
        pstmt = conn.prepareStatement(GET_SHARCH_RESULT2_WITHOUT_PAGE,
                                      ResultSet.TYPE_SCROLL_SENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
        pstmt.setString(1, examinee_id);
        pstmt.setString(2, name);
        pstmt.setString(3, sex);
        pstmt.setString(4, organization_id);
        pstmt.setString(5, state);
        pstmt.setString(6, operation);
        pstmt.setString(7, post_index);
      }
      rs = pstmt.executeQuery();

      while(rs.next()){
        examinee = new Examinee();
        examinee.setExaminee_id(rs.getString(1));
        examinee.setPassword(rs.getString("PASSWORD"));
        examinee.setName(rs.getString("NAME"));
        examinee.setSex(rs.getString("SEX"));
        examinee.setSexName(rs.getString("SEXNAME"));
        examinee.setAge(rs.getString("AGE"));
        examinee.setOrganization_id(rs.getString("ORGANIZATION_ID"));
        examinee.setOrganizationName(rs.getString("ORGANIZATIONNAME"));
        examinee.setPost_index(rs.getString("POST_INDEX"));
        examinee.setPostName(rs.getString("POSTNAME"));
        examinee.setState(rs.getString("STATE"));
        examinee.setStateName(rs.getString("STATENAME"));
        examinee.setOperation(rs.getString("OPERATION"));
        examinee.setOperationName(rs.getString("OPERATIONNAME"));
        examinee.setEducation_index(rs.getString("EDUCATION_INDEX"));
        examinee.setEducationName(rs.getString("EDUCATIONNAME"));
        examinee.setAddress(rs.getString("ADDRESS"));
        examinee.setPhone(rs.getString("PHONE"));
        examinee.setMobile(rs.getString("MOBILE"));
        examinee.setEmail(rs.getString("EMAIL"));
        examinee.setRemark(rs.getString("REMARK"));

        list.add(examinee);

      }
    } catch (SQLException ex) {
      ex.printStackTrace();
    } finally {
      try {
        rs.close();
        rs = null;
        pstmt.close();
        pstmt = null;
        conn.close();
        conn = null;
      } catch (SQLException ex1) {
        ex1.printStackTrace();
      }
      
    }
    return list;
  }





  public boolean isUser(LogonForm logonForm) {
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    boolean isUser = false;

    try {
      pstmt = conn.prepareStatement(IS_USER);
      pstmt.setString(1, logonForm.getUserName());
      rs = pstmt.executeQuery();
      if (rs.next()) {
        if (rs.getString(1).equals(logonForm.getPassword())) {
          isUser = true;
        }
      }
    } catch (SQLException ex) {
      ex.printStackTrace();
    } finally {
      try {
        rs.close();
        rs = null;
        pstmt.close();
        pstmt = null;
        conn.close();
        conn = null;
      } catch (SQLException ex1) {
        ex1.printStackTrace();
      }
    }
    return isUser;
  }

  public boolean isAdminUser(LogonForm logonForm) {
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    boolean isAdminUser = false;

    try {
      pstmt = conn.prepareStatement(IS_ADMINUSER);
      pstmt.setString(1,logonForm.getUserName());
      pstmt.setString(2,logonForm.getPassword());
      rs = pstmt.executeQuery();
      while(rs.next()){
      	isAdminUser=true;
      	return isAdminUser;
      }
    } catch (SQLException ex) {
      ex.printStackTrace();
    } finally {
      try {
        rs.close();
        rs = null;
        pstmt.close();
        pstmt = null;
        conn.close();
        conn = null;
      } catch (SQLException ex1) {
        ex1.printStackTrace();
      }
    }
    return isAdminUser;
  }
  
  
  
  /**
   * hasUser
   *
   * @param examinee_id String
   * @return boolean
   */
  public boolean hasUser(String examinee_id) {
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    boolean overlap = false;
    try {
      pstmt = conn.prepareStatement(HAS_USER);
      pstmt.setString(1, examinee_id);
      rs = pstmt.executeQuery();
      if (rs.next()) {
        overlap = true;
      }
    } catch (SQLException ex) {
      ex.printStackTrace();
    } finally {
      try {
        rs.close();
        rs = null;
        pstmt.close();
        pstmt = null;
        conn.close();
        conn = null;
      } catch (SQLException ex1) {
        ex1.printStackTrace();
      }

      
    }
    return overlap;
  }

  /**
   * re-initialize password as examinee_id
   * @param examinee_id String
   * @throws SQLException
   */
  public void reInitPwd(String examinee_id) throws SQLException {
    PreparedStatement pstmt = null;
    try {
      pstmt = conn.prepareStatement(RE_INIT_PWD);
      pstmt.setString(1, examinee_id);
      pstmt.executeUpdate();
    } catch (SQLException ex) {
      ex.getStackTrace();
      ex.printStackTrace();
    } finally {
      try {
        pstmt.close();
        pstmt = null;
        conn.close();
        conn = null;
      } catch (SQLException ex1) {
        ex1.printStackTrace();
      }
    }
  }

  /**
   * updatePwd password as examinee_set
   * @param examinee_id String
   * @throws SQLException
   */
  public void updatePwd(String examinee_id, String oldPwd, String newPwd) throws
      SQLException {
    PreparedStatement pstmt = null;
    try {
      pstmt = conn.prepareStatement(UPDATE_PWD);
      pstmt.setString(1, newPwd);
      pstmt.setString(2, examinee_id);
      pstmt.setString(3, oldPwd);
      pstmt.executeUpdate();
    } catch (SQLException ex) {
      ex.getStackTrace();
      throw new SQLException("SQLExction on : ExamineeDAO.updatePwd()");
    } finally {
      try {
        pstmt.close();
        pstmt = null;
        conn.close();
        conn = null;
      } catch (SQLException ex1) {
        ex1.printStackTrace();
      }
    }
  }
  /////
  public int insertuser(String sql) throws
  SQLException {
	  int i =0;
PreparedStatement pstmt = null;
try {
    pstmt = conn.prepareStatement(sql);
    i= pstmt.executeUpdate();
    return i;
}  catch (SQLException ex) {
  ex.getStackTrace();
  throw new SQLException("SQLExction on : ExamineeDAO.updatePwd()");
} finally {
  try {
    pstmt.close();
    pstmt = null;
    conn.close();
    conn = null;
  } catch (SQLException ex1) {
    ex1.printStackTrace();
  }
}
}
}

⌨️ 快捷键说明

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