[英]Error with a prepared statement with named placeholders in PHP with mySQL
[英]Several close placeholders in postgres prepared statement
我正在使用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...
...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) ...
如何将这两个占位符或其他东西分开?
Postgres不允许您将排序方向指定为参数。 您需要为asc
和desc
顺序创建不同的查询字符串,并选择其中一个执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.