我正在尝试创建一个groovy脚本,该脚本将从数据库中的表中提取值,然后将用于SOPAUI中的请求中。Groovy SQL语句语法错误
问题是,在我的SQL查询中,我有一个where子句,其中包含带单引号的字符串值,在运行时会返回错误。
import groovy.sql.Sql
import java.sql.Driver
def sql = Sql.newInstance ('jdbc:sqlserver://hostname\\INSTANCE1;Database=DB;integratedSecurity=true','com.microsoft.sqlserver.jdbc.SQLServerDriver')
row = sql.firstRow('SELECT TOP 1 m.ID [DB].[dbo].[AOTableName] AS m INNER JOIN [DOC_MASTER_dev].[dbo].[AOMatterTableName] AS c ON m.SystemID = c.ID WHERE (m.Status = 0) AND (c.Code = "'ESB'") order by newid(), m.DateAddedForReplication desc ')
.......
的误差小于:
ERROR:org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script25.groovy: 6: unexpected token: ESB @ line 6, column 231. us = 0) AND (c.Code = "'ESB'") ord ^ org.codehaus.groovy.syntax.SyntaxException: unexpected token: ESB @ line 6, column 231. at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:140) at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:108) at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:236) at org.codehaus.groovy.control.CompilationUnit$1.call(......
脚本将只是转换成字符串的其余部分与设定值从DB财产,可以然后在请求中使用。
任何想法,我做错了什么?
您可能需要阅读此:http://docs.groovy-lang.org/ latest/html/documentation/index.html#all-strings – SiKing