Home > Software engineering >  error message when calling update() function : The conversion from UNKNOWN to UNKNOWN is unsupported
error message when calling update() function : The conversion from UNKNOWN to UNKNOWN is unsupported

Time:02-04

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.

CodePudding user response:

Some of the arguments cannot be converted by the driver. You can try to comment them one by one to find the issue.

Usually, passing the value as a string do the trick:

.addValue("tradercode", entity.getTraderCode().toString())

CodePudding user response:

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);
}
  •  Tags:  
  • Related