我想要触发一个更新查询,通常使用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有什么想法吗?
发布于 2011-10-17 18:49:54
您需要告诉Groovy字段名是静态的,不应该用? by using Sql.expand替换
sql.executeUpdate("update MYTABLE l set ${Sql.expand(makeQueryString(propertiesToUpdate))} where l.id = ${someobj.id}")https://stackoverflow.com/questions/7792571
复制相似问题