Ejemplo n.º 1
0
  public IUserInfo FindUserByPass(Object pwd) {
    IUserInfo user = UserInfo.Empty();
    Connection conn = connect();

    String sql = "SELECT id, username, pass from users where pass LIKE ?";
    PreparedStatement select;

    try {
      select = conn.prepareStatement(sql);

      select.setString(1, pwd.toString());

      ResultSet result = select.executeQuery();
      if (result.next()) { // process results one row at a time
        int id = result.getInt(1);
        String username = result.getString(2);
        String pass = result.getString(3);

        user = new UserInfo(username, pass);
      } else {
        System.out.println("Mật khẩu không đúng");
      }
      select.close();
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {

      _connMan.CloseConnection(conn);
    }
    return user;
  }
Ejemplo n.º 2
0
  // region FindByName
  public IUserInfo FindByName(String name) {
    IUserInfo user = null;
    Connection conn = connect();
    String sql = "SELECT id, username, pass from users where username LIKE ?";
    PreparedStatement select;

    try {
      //			JOptionPane.showMessageDialog(null, name);
      select = conn.prepareStatement(sql);

      select.setString(1, name);

      ResultSet result = select.executeQuery();
      if (result.next()) { // process results one row at a time
        int id = result.getInt(1);
        String username = result.getString(2);
        String pass = result.getString(3);
        System.out.println(String.format("line 93 UserDAO: pass=%s", pass));
        user = new UserInfo(username, pass);
      } else {
        System.out.println("người dùng không đúng");
      }
      select.close();
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {

      _connMan.CloseConnection(conn);
    }
    return user;
  }