语法错误在或靠近”$1″处。 JDBC PostgreSQL -> 设置 var = ?

huangapple go评论55阅读模式
英文:

Syntax error at or near "$1" jdbc postgres -> SET var=?

问题

尝试执行以下代码:

this.getSessionFactory().getCurrentSession()
        .createNativeQuery("SET app.variable = :variable")
        .setParameter("variable","variableValue")
        .executeUpdate();

它给我返回了以下错误:

org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
  Position: 26

我不确定这是JDBC还是PostgreSQL的错误。

当我在DBeaver中使用绑定变量时,似乎不是PostgreSQL的问题,查询正常工作。

尝试创建一个准备好的语句执行相同的查询结果相同。

英文:

Trying to execute the following code :

this.getSessionFactory().getCurrentSession()
        .createNativeQuery("SET app.variable = :variable")
        .setParameter("variable","variableValue")
        .executeUpdate();

It is giving me the following error :

org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
  Position: 26

I'm not sure if this is a bug in JDBC or PostgreSQL.

It seems not a PostgreSQL issue as when I use the DBeaver using bind variables the query works fine.

Tried the same query by creating a prepared statement as well and the Result was same.

答案1

得分: 3

SQL语句中的SET不接受参数。只有SELECTVALUESINSERTUPDATEDELETEMERGE支持参数。

英文:

The SQL statement SET accepts no parameters. Only SELECT, VALUES, INSERT, UPDATE, DELETE and MERGE do.

huangapple
  • 本文由 发表于 2023年2月10日 07:11:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75405418.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定