The most straightforward way is to create a class that contains fields that correspond to your database columns (name, surname, address). Then, as you already say yourself, create an instance of this class for each row in the table and store them in a List
.
A Set
will not be appropriate, since most Set
implementations (for example HashSet
) are not ordered, so if your data is sorted, the Set
won't preserve the sort order. A List
is ordered.
To get the data out of the database, you could simply program it in JDBC yourself, which is straightforward in this case: open a connection to the database, execute an SQL query, loop through the rows in the ResultSet
, create an object for each row and fill it with the data that you get from the ResultSet
, store the created objects in a List
.
When your data model becomes more complicated than a single class, it might be worth it to use an object-relational mapping (ORM) framework. Java has a standard API for this, Java Persistence API (JPA). Hibernate is a popular implementation of this API.