Creating row mapper

RowMapper is an interface that is provided by the Spring JDBC. This is used to map a row with a Java object and to fetch data from the database. It uses the query() function of the JdbcTemplate class. Let's create a RowMapper interface named UserRowMapper.kt.

Here is the code of this interface:

class UserRowMapper : RowMapper<UserModel> {

@Throws(SQLException::class)
override fun mapRow(row: ResultSet, rowNumber: Int): UserModel? {
return UserModel(row.getInt("id"),
row.getString("name"),
row.getString("email"),
row.getString("contact_number"))
}
}

In this code, we extended RowMapper<UserModel> and overrode the mapRow where we return the UserModel.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.179.85