【发布时间】:2018-06-05 08:22:40
【问题描述】:
我有一个简单的 sql 查询,它将版本增加 1 并返回 postgresql 中的当前值,例如:
UPDATE table SET version = version + 1 where id = 'XXX' RETURNING version
但是我无法在 jdbcTemplate.update 语句中使用它:
int version = jdbcTemplate.update(sqlString, new Object[] {id});
抛出异常:
没有预期的结果时返回了结果
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [UPDATE table SET version = version + 1 where id = ? RETURNING version]; A result was returned when none was expected.; nested exception is org.postgresql.util.PSQLException: A result was returned when none was expected.
RETURNING 语句的正确使用方法是什么?
【问题讨论】:
-
抛出什么异常!
-
org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是 org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [UPDATE table SET version = version + 1 where id = ?返回版本];预期没有结果时返回结果。嵌套异常是 org.postgresql.util.PSQLException: A result was returned when none is expected.
标签: java sql postgresql jdbc jdbctemplate