Code example for NamedParameterJdbcTemplate

Methods: update

0
		// populate the id 
		person.setId(newId); 
	} 
 
	public void update(Person person) { 
		int numRowsAffected = jdbcTemplate.update( 
				"update person set user_name = :userName, first_name = :firstName, last_name = :lastName where id = :id", 
				new BeanPropertySqlParameterSource(person)); 
		 
		if (numRowsAffected == 0) { 
			throw new PersonNotFoundException("No person found for id: " + person.getId()); 
		} 
	} 
 
	private static class PersonRowMapper implements RowMapper<Person> { 
		public Person mapRow(ResultSet res, int rowNum) throws SQLException { 
			Person p = new Person(); 
			p.setId(res.getInt("id")); 
			p.setUserName(res.getString("user_name")); 
			p.setFirstName(res.getString("first_name")); 
Experience pair programming with AI  Get Codota for Java