Mapping a JDBC ResultSet to an object

前端 未结 8 1268
生来不讨喜
生来不讨喜 2020-12-04 18:14

I have a user class that has 16 attributes, things such as firstname, lastname, dob, username, password etc... These are all stored in a MySQL database and when I want to re

8条回答
  •  醉话见心
    2020-12-04 18:47

    I would like to hint on q2o. It is a JPA based Java object mapper which helps with many of the tedious SQL and JDBC ResultSet related tasks, but without all the complexity an ORM framework comes with. With its help mapping a ResultSet to an object is as easy as this:

    while(rs.next()) {
        users.add(Q2Obj.fromResultSet(rs, User.class));
    }
    

    More about q2o can be found here.

提交回复
热议问题