问题
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
Option1
sql.executeUpdate "UPDATE " +grid1+" t0 set XXX='$status' WHERE t0.YYY='$grid'"
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.
Hope this helps someone
回答1:
You should do:
sql.executeUpdate "UPDATE ${Sql.expand(grid1)} t0 set XXX=$status WHERE t0.YYY=$grid"
Or
def bql = "UPDATE ${Sql.expand(grid1)} t0 set XXX=$status WHERE t0.YYY=$grid"
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
来源:https://stackoverflow.com/questions/43782702/using-prepared-statement-in-groovy