Exemplo n.º 1
0
  public int login(Student stu) {
    // conn=DBConnector.Getconnect();
    conn = DBConnector.Getconnect();
    int result = 1;
    String sql = "select password,role from student where email=?";
    try {
      pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, stu.getEmail());
      rs = pstmt.executeQuery();
      if (rs.next()) {
        String password = rs.getString("password");
        if (password.equals(stu.getPassword())) {
          result = RESULT.SUCCESS;
          stu.setRole(rs.getInt("role"));
        } else {
          result = RESULT.PASSWORD_ERROR;
        }
      } else {
        result = RESULT.USER_INVALID;
      }

    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      DBConnector.closeResult(rs);
      DBConnector.closePreparedStatement(pstmt);
      DBConnector.closeConn(conn);
    }

    return result;
  }
Exemplo n.º 2
0
  public String getpassword(Student stu) {
    conn = DBConnector.Getconnect();
    String sql = "select password from student where email=?";
    try {
      pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, stu.getEmail());
      rs = pstmt.executeQuery();
      if (rs.next()) {
        return rs.getString("password");
      }

    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      DBConnector.closeResult(rs);
      DBConnector.closePreparedStatement(pstmt);
      DBConnector.closeConn(conn);
    }

    return null;
  }