Introduction
We want to show some basic queries for the JDBC template. if you’re going to try out some queries, feel free to use my starter project with in-memory database
How to insert with Named parameters
For Insert, you can do simple execute. I will show two examples, the later one with named parameters
Java
Here we just insert directly in our customers table with the columns „first_name“ and „last_name“ with the values „Martin“ and „codenest“.
Now one example for named parameters. We have two options. First with simple jdbctemplate
Java
How to insert with NamedParameterJdbcTemplate
In this case, we create a NamedParameterJdbcTemplate. As the name suggests, it is optimized for named parameter queries.
Java
Here we also insert one dataset. But create a Map for the named parameters with the keys „firstName“, and „lastName“.