Mapping a row from a SQL data to a Java object

前端 未结 9 1173
悲哀的现实
悲哀的现实 2021-02-06 02:34

I have a Java class with instance fields (and matching setter methods) that match the column names of a SQL database table. I would like to elegantly fetch a row from the table

9条回答
  •  一整个雨季
    2021-02-06 03:04

    I recommend using Spring JDBC. You don't need to use the rest of Spring to use their JDBC library. It will manage connections for you (no more closing Connection, Statement, or ResultSet) and has many conveniences, including row mapping.

    We've retrofitted legacy code with Spring JDBC with little trouble.

    Here is a presentation (PDF) of an overview of Spring JDBC. It's a few years old but it still works essentially the same, even without letting Spring inject the dependencies.

    Spring JDBC Presentation PDF

提交回复
热议问题