コード例 #1
0
  public User checkForWinner(int gameid) {
    User u = new User();
    try (PreparedStatement statement = connection.prepareStatement(CHECK_FOR_WINNER)) {
      statement.setInt(1, gameid);
      statement.execute();

      ResultSet rs = statement.getResultSet();
      while (rs.next()) {
        u.setUserID(rs.getInt("userid"));
        u.setFirstName(rs.getString("first"));
        u.setLastName(rs.getString("last"));
        u.setWinner(rs.getInt("winner"));
      }
    } catch (Exception ex) {
    }
    return u;
  }
コード例 #2
0
  public User getUserByEmail(String email) {
    User u = new User();
    try (PreparedStatement statement = connection.prepareStatement(SELECT_USER_EMAIL)) {
      statement.setString(1, email);
      statement.execute();

      ResultSet rs = statement.getResultSet();
      while (rs.next()) {
        u.setUserID(rs.getInt("userid"));
        u.setFirstName(rs.getString("first"));
        u.setLastName(rs.getString("last"));
        u.setIsAdmin(rs.getInt("admin") == 1);
        u.setWins(rs.getInt("wins"));
        u.setLoses(rs.getInt("loses"));
        u.setEmail(rs.getString("email"));
      }
    } catch (Exception ex) {
    }
    return u;
  }
コード例 #3
0
  public List<User> getAllUsers() {
    List<User> users = new ArrayList<User>();
    try (PreparedStatement statement = connection.prepareStatement(SELECT_ALL_USERS)) {

      ResultSet rs = statement.executeQuery();
      while (rs.next()) {
        User u = new User();
        u.setUserID(rs.getInt("userid"));
        u.setFirstName(rs.getString("first"));
        u.setLastName(rs.getString("last"));
        u.setWins(rs.getInt("wins"));
        u.setLoses(rs.getInt("loses"));
        u.setEmail(rs.getString("email"));
        users.add(u);
      }
    } catch (Exception ex) {
    }
    return users;
  }