JdbcTemplate’s update() method executes SQL that inserts or modifies database data. Pass the SQL string followed by values for its ? parameters; unlike query(), it does not require ResultSet mapping. section 3.1.2
Insert an ingredient
A repository can save an Ingredient with jdbcTemplate.update("insert into Ingredient (id, name, type) values (?, ?, ?)", ingredient.getId(), ingredient.getName(), ingredient.getType().toString());. The three values replace the SQL placeholders, after which the repository returns the ingredient. section 3.1.2
Listing 3.6 Inserting data with JdbcTemplate
@Override
public Ingredient save(Ingredient ingredient) {
jdbcTemplate.update(
"insert into Ingredient (id, name, type) values (?, ?, ?)",
ingredient.getId(),
ingredient.getName(),
ingredient.getType().toString());
return ingredient;
}
View the complete save method using update() to insert an Ingredient row. section 3.1.2


