Question: I want to create a list with my database field values.
There are 2 columns, name and surname.
I want to create a list that stores all names in name column in a field and then add to my DTO.

Is this possible?

Answer: 
JDBC unfortunately doesn't offer any ways to conveniently do this in a one-liner. But there are other APIs, such as [jOOQ](http://www.jooq.org) (disclaimer: I work for the company behind jOOQ):

```
List<DTO> list =
DSL.using(connection)
   .fetch("SELECT first_name, last_name FROM table")
   .into(DTO.class);

```

Or [Spring JDBC](http://projects.spring.io/spring-data/)

```
List<DTO> list =
new JdbcTemplate(new SingleConnectionDataSource(connection, true))
   .query("SELECT first_name, last_name FROM table", (rs, rowNum) ->
       new DTO(rs.getString(1), rs.getString(2));

```

Or [Apache DbUtils](http://commons.apache.org/proper/commons-dbutils/):

```
List<DTO> list =
new QueryRunner()
   .query(connection, 
          "SELECT first_name, last_name FROM table", 
          new ArrayListHandler())
   .stream()
   .map(array -> new DTO((String) array[0], (String) array[1]))
   .collect(Collectors.toList());

```

I've used Java 8 for the Spring JDBC / Apache DbUtils examples, but it can be done with older versions of Java as well.
What worked for me is:

```
ResultSetMetaData rsmd = rs.getMetaData();
         int columnCount = rsmd.getColumnCount();

         ArrayList<String> resultList= new ArrayList<>(columnCount);
         while (rs.next()) {
             int i = 1;
             while(i <= columnCount) {
                 resultList.add(rs.getString(i++));
             }
         }
         return resultList;

```