PreparedStatementSetter
?It is a callback interface used by JdbcTemplate
after PreparedStatement
is created to set the values in the statement object.
PreparedStatementSetter
is also functional interface, so we will use lambda expression in this example to demonstrate PreparedStatementSetter
usage. We will use it in update
method of JdbcTemplate
.
int updateCount = jdbcTemplate.update("insert into product(name, category, description) values(?,?,?)", ps -> {
ps.setString(1, "Lenovo Bag");
ps.setString(2, "bag");
ps.setString(3, "Handcrafted bags by Lenovo");
});
log.info(() -> String.format("Product inserted: %d", updateCount));
You can see the full example code on Github.