In this recipe, we will add a DAO method to update an existing row in the database with an object's fields.
Use an SQL update
query and execute it using the update()
method:
public void update(User user) { String sql = "update user set first_name=?, age=? where id=?"; jdbcTemplate.update(sql, user.getFirstName(), user.getAge(), user.getId()); }