构造查询时 Gsql 不执行
我想触发更新查询,通常使用 groovy 我们做类似的事情:
sql.executeUpdate("update MYTABLE l set field1 where l.id = ${someobj.id}")
上面的工作完美,但我的问题是我不知道我需要更新多少参数。所以我做了一个返回的函数 propertytoudate1 = 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
ANY IDEAS ??
I want to fire an update query , normally using groovy we do something like :
sql.executeUpdate("update MYTABLE l set field1 where l.id = ${someobj.id}")
The above works perfectly but my problem is that i dont know ahead how many parameters i need to update. So i made a function which returns the
properttoudate1 = value1 , propertytoupdate2 = value2 .. and so on..
Then i modified the above query to
sql.executeUpdate("update MYTABLE l set ${makeQueryString(propertiesToUpdate)} where l.id = ${someobj.id}")
Now it gives me the error::
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
ANY IDEAS ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要告诉 Groovy 该字段名是静态的,不应替换为
?
:You need to tell Groovy that the fieldname is a static, and shouldnt be replaced with
?
by usingSql.expand
: