The below function should perform an insert into database in using NamedJdbcTemplate
:
public int create(Customer entity) {
NamedParameterJdbcTemplate template = getDataSource(TENANT, ENVIRONMENT);
MapSqlParameterSource paramMap = new MapSqlParameterSource()
.addValue("compid", entity.getCompID())
.addValue("tradercode", entity.getTraderCode())
.addValue("title", entity.getTitle())
// ... other params
return template.update(INSERT_QUERY, paramMap);
}
However I get this error message when calling
com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from UNKNOWN to UNKNOWN is unsupported.
after trying a bit more, by providing the sqlType
in MapSqlParameterSource
seems to resolve the issue:
public int create(Customer entity) {
NamedParameterJdbcTemplate template = getDataSource(TENANT, ENVIRONMENT);
MapSqlParameterSource paramMap = new MapSqlParameterSource()
.addValue("compid", entity.getCompID(), Types.VARCHAR)
.addValue("tradercode", entity.getTraderCode(), Types.VARCHAR)
.addValue("title", entity.getTitle(), Types.VARCHAR)
// ... other params
return template.update(INSERT_QUERY, paramMap);
}