READ

Find the code snippet pertaining to the read operation. The following function will return a list of all the user's details:

override fun getAllUserList(): List<UserModel> {
val selectAllSql = "SELECT * FROM users"
return jdbcTemplate.query(selectAllSql, UserRowMapper())
}

selectAllSql = "SELECT * FROM users" is the query to fetch all the users from user the table. jdbcTemplate.query() will execute the query and fetch the data.

This following function will get a user's details based on id:

override fun getUserByID(id: Int): UserModel? {
val selectAllSql = "SELECT * FROM users WHERE id = ?"
return jdbcTemplate.queryForObject(selectAllSql, UserRowMapper(), id)
}

selectAllSql = "SELECT * FROM users WHERE id = ?" is the query to fetch a user from the user table by using the ID. jdbcTemplate.queryForObjec() will execute the query and fetch the data.

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

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