gpt4 book ai didi

sql - Gsql在构造查询时未执行

转载 作者:行者123 更新时间:2023-12-02 14:46:52 24 4
gpt4 key购买 nike

我想触发一个更新查询,通常使用groovy我们做类似的事情:

sql.executeUpdate("update MYTABLE l set field1  where l.id = ${someobj.id}")

以上工作完美,但我的问题是我事先不知道需要更新多少个参数。所以我做了一个函数返回
properttoudate1 = value1,propertytoupdate2 = value2 ..依此类推。
然后我将上面的查询修改为
sql.executeUpdate("update MYTABLE l set ${makeQueryString(propertiesToUpdate)} where l.id = ${someobj.id}")

现在它给了我错误:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''PROPERTY1 = 1' where l.id = 'PROPERTVALUE1'' at line 1

有任何想法吗 ??

最佳答案

您需要告诉Groovy字段名是静态的,不应将其替换为? by using Sql.expand :

sql.executeUpdate("update MYTABLE l set ${Sql.expand(makeQueryString(propertiesToUpdate))} where l.id = ${someobj.id}")

关于sql - Gsql在构造查询时未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7792571/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com