In Spring, how can I insert data in table using JdbcTemplate. Can anyone please provide me a code sample for doing this.
Use jdbcTemplate.update(String sql, Object... args)
method:
jdbcTemplate.update(
"INSERT INTO schema.tableName (column1, column2) VALUES (?, ?)",
var1, var2
);
or jdbcTemplate.update(String sql, Object[] args, int[] argTypes)
, if you need to map arguments to SQL types manually:
jdbcTemplate.update(
"INSERT INTO schema.tableName (column1, column2) VALUES (?, ?)",
new Object[]{var1, var2}, new Object[]{Types.TYPE_OF_VAR1, Types.TYPE_OF_VAR2}
);