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; }
public User getUserByUserID(int userid) { User u = new User(); try (PreparedStatement statement = connection.prepareStatement(SELECT_USER)) { statement.setInt(1, userid); 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.setWins(rs.getInt("wins")); u.setLoses(rs.getInt("loses")); u.setEmail(rs.getString("email")); } } catch (Exception ex) { } return u; }
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; }