public <E> List<E> list(RowMapper<E> rowMapper) throws SQLException { List<E> result = new LinkedList<>(); try (ResultSet resultSet = execute(toString())) { int rowNum = 0; while (resultSet.next()) { E obj = rowMapper.convert(resultSet, rowNum++); result.add(obj); } } return result; }
public <E> E single(RowMapper<E> rowMapper) throws SQLException { E result = null; try (ResultSet resultSet = execute(toString())) { if (resultSet.next()) { result = rowMapper.convert(resultSet, 1); if (resultSet.next()) { throw new SQLException("The query returned more than one result"); } } } return result; }