データベースのテーブルから値を抽出する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/最新/ html/documentation/index.html#すべての文字列 – SiKing