January 2019
Intermediate to advanced
392 pages
10h 11m
English
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.
Read now
Unlock full access