我正在嘗試創建一個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