Skip to main content


Showing posts with the label PreparedStatementSetter example in Spring JDBC

Spring JDBC PreparedStatementSetter example

What is PreparedStatementSetter? It is a callback interface used by JdbcTemplate after PreparedStatement is created to set the values in the statement object. How to use it? PreparedStatementSetter is also functional interface, so we will use lambda expression in this example to demonstrate PreparedStatementSetter's 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"); }); -> String.format("Product inserted: %d", updateCount)); You can get the full code of this example from here .