Untitled

mail@pastecode.io avatar
unknown
java
a year ago
646 B
2
Indexable
Never
public List<User> findAllUser() {
    List<User> resultList = new ArrayList<>();
    try (Connection connection = CustomDataSource.getInstance().getConnection();
         PreparedStatement ps = connection.prepareStatement(FIND_ALL_USER_SQL)) {
        try (ResultSet rs = ps.executeQuery()) {
            while (rs.next()) {
                resultList.add(new User(rs.getLong(1),
                        rs.getString(2),
                        rs.getString(3),
                        rs.getInt(4)));
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return resultList;
}