In Java - How to map resultSet into a complex object?

前端 未结 4 1286
生来不讨喜
生来不讨喜 2021-01-24 02:12

How can I map a resultset from a few tables into a complex object? let me elaborate:

Lets say I have these 2 classes:

public class User {
    private int         


        
4条回答
  •  难免孤独
    2021-01-24 02:56

    Maybe try something like this:

    ArrayList users = new ArrayList();
    while(resultSet.next)
    {
         users.add(new User(resultSet.getString("id"), resultSet.getString("fname"), resultSet.getString("lname"));
         //you can also add your countries to an array list
    }
    

提交回复
热议问题