在Groovy中使用准备好的语句 [英] Using prepared statement in Groovy
本文介绍了在Groovy中使用准备好的语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是出于测试目的(自动测试)SoapUI
this is for testing purposes (automatic testing) SoapUI
def status = testRunner.testCase.getPropertyValue( "Status" )
def grid = testRunner.testCase.getPropertyValue( "Grid" )+"_V"
def grid1
if (["TABLE1","TABLE2"].contains(grid))
grid1 ="HUBCFG."+grid
else grid1 = "SDM."+grid
选项1
Option1
sql.executeUpdate "UPDATE " +grid1+" t0 set XXX='$status' WHERE t0.YYY='$grid'"
选项2
Option2
String bql = "UPDATE $grid1 t0 set XXX='$status' WHERE t0.YYY='$grid'"
sql.executeUpdate bql
sql.commit()
log.info("Successfully committed "+grid1+ " To " + status)
我在任何地方都找不到清晰的答案,所以我将它们拼凑在一起.
i didnt find the answers clear cut anywhere, so i scraped them together.
希望这对某人有帮助
推荐答案
您应该这样做:
sql.executeUpdate "UPDATE ${Sql.expand(grid1)} t0 set XXX=$status WHERE t0.YYY=$grid"
或
def bql = "UPDATE ${Sql.expand(grid1)} t0 set XXX=$status WHERE t0.YYY=$grid"
将为您添加单引号,并且Sql.expand允许您将诸如表名之类的内容嵌入到生成的模板化Groovy字符串中
The single quotes will be added for you, and Sql.expand allows you to embed things like table names into the resultant templated Groovy String
这篇关于在Groovy中使用准备好的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文