【发布时间】:2011-11-09 09:43:21
【问题描述】:
我将 Spring JbdcTemplate 与 Postgres 一起使用。
遇到 Postrgres JDBC 内部准备好的语句实现的问题原因
我的查询字符串是:
private static final String SELECT_ALL_PARTIALLY =
"SELECT login, added FROM admin ORDER BY ? ? OFFSET ? LIMIT ?";
我想像这样使用它:
List matches = getJdbcTemplate().query(SELECT_ALL_PARTIALLY,
(new Object[]{
column, // "login" or "added"
order, // "asc" or "desc"
offset,
limit
}),
new RowMapper() {
...
问题在于...ORDER BY ? ? OFFSET...
org.postgresql.util.PSQLException: ERROR: syntax error at or near "$2"
Position: 61
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:273)
at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:648) ...
我怎样才能分开这两个占位符之类的?
【问题讨论】:
标签: sql spring postgresql jdbc prepared-statement