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: 
**Steps you can follow**: -

* First you need to have a `List<String>` that will store all your names. Declare it like this: -

```
List<String> nameList = new ArrayList<String>();

```
* Now, you have all the records fetched and stored in `ResultSet`. So I assume that you can iterate over `ResultSet` and get each `values` from it. You need to use `ResultSet#getString` to fetch the `name`.
* Now, each time you fetch one record, get the `name` field and add it to your list.

```
while(resultSet.next()) {
    nameList.add(resultSet.getString("name"));
}

```
* Now, since you haven't given enough information about your `DTO`, so that part you need to find out, how to add this `ArrayList` to your `DTO`.
* The above `list` only contains `name` and not `surname` as you wanted only `name`. But if you want both, you need to create a custom DTO `(FullName)`, that
contains `name` and `surname` as fields. And instantiate it from
every `ResultSet` and add it to the `List<FullName>`
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;

```