org.h2.jdbc.JdbcSQLNonTransientException: Неизвестный тип данных при обновлении БД
Пытаюсь сделать обновление БД по условию используя JdbcTemplate.update
public Clothes updateClothes(Clothes clothes) {
String type_Clothes = clothes.getTypeClothes().toString();
String size = clothes.getSize().toString();
String color = clothes.getColor().toString();
int cotton = clothes.getCotton();
int quantity = clothes.getQuantity();
String sql = "merge into CLOTHES_REP c " +
"using (SELECT ? as type_Clothes, ? as size, ? as color, ? as cotton, ? as quantity from dual) d " +
"on (c.type_Clothes = d.type_Clothes, c.size = d.size, c.color = d.color, c.cotton = d.cotton) " +
"when matched then update " +
"set c.quantity = d.quantity " +
"when not matched then insert (type_Clothes, size, color, cotton, quantity) " +
"values(d.type_Clothes, d.size, d.color, d.quantity)";
jdbcTemplate.update(sql, type_Clothes, size, color, cotton, quantity);
return clothes;
}
вылетает ошибка:
Unknown data type: "TYPE_CLOTHES"; SQL statement: merge into CLOTHES_REP c using (SELECT ? as type_Clothes, ? as size, ? as color, ? as cotton, ? as quantity from dual) d on (c.type_Clothes = d.type_Clothes, c.size = d.size, c.color = d.color, c.cotton = d.cotton) when matched then update set c.quantity = d.quantity when not matched then insert (type_Clothes, size, color, cotton, quantity) values(d.type_Clothes, d.size, d.color, d.quantity) [50004-214];
пользовался подсказками: How to insert/update a single record using a MERGE statement with Spring JDBC
На всякий случай кусок работающего запроса:
jdbcTemplate.update(
"insert into CLOTHES_REP (type_Clothes, size, color, cotton, quantity) values (?, ?, ?, ?, ?)",
clothes.getTypeClothes().toString(),
clothes.getSize().toString(),
clothes.getColor().toString(),
clothes.getCotton(),
clothes.getQuantity());
Источник: Stack Overflow на русском