2012-11-06 47 views
2

我試圖進行選擇這樣的:常規 - SQL eachRow命名參數地圖

def queries = [ 
    [ 
     paramQuey: "", 
     mainQuery: "SELECT * FROM SOME_TABLE" 
    ], 
    [ 
     paramQuey: "SELECT SOME_COLUMN AS COUNT FROM A_TABLE WHERE SOMETHING=3", 
     mainQuery: "SELECT * FROM OTHER_TABLE WHERE ROWNUM<:COUNT" 
    ] 
] 

queries.each { 
    def params = [:] 
    if(!it.paramQuery.isEmpty()) { 
     params = sql.firstRow(it.paramQuery) 
    } 
    sql.eachRow(mainQuery, params) { //<--here's my problem 
     //do something 
    } 
} 

然而,程序引發

Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: groovy.sql.Sql.eachRow() is applicable for argument types: (java.lang.String, java.util.LinkedHashMap, MyClass$_execute_closure4) values: [SELECT * FROM SOME_TABLE, [:], [email protected]] 
Possible solutions: eachRow(java.lang.String, groovy.lang.Closure), eachRow(java.lang.String, groovy.lang.Closure, groovy.lang.Closure), eachRow(java.lang.String, java.util.List, groovy.lang.Closure), eachRow(groovy.lang.GString, groovy.lang.Closure), eachRow(groovy.lang.GString, groovy.lang.Closure, groovy.lang.Closure), eachRow(java.lang.String, int, int, groovy.lang.Closure) 

這清楚地表明,有與處理eachRow沒有方法命名參數。然而,根據http://groovy.codehaus.org/api/groovy/sql/Sql.html有:

void eachRow(java.lang.String sql, java.util.Map params, Closure closure) 
    void eachRow(java.lang.String sql, java.util.Map params, Closure metaClosure, Closure rowClosure) 
    void eachRow(java.lang.String sql, java.util.Map map, Closure metaClosure, int offset, int maxRows, Closure rowClosure) 
    void eachRow(java.lang.String sql, java.util.Map params, int offset, int maxRows, Closure closure) 
    void eachRow(java.util.Map params, java.lang.String sql, Closure closure) 
    void eachRow(java.util.Map params, java.lang.String sql, Closure metaClosure, Closure rowClosure) 
    void eachRow(java.util.Map map, java.lang.String sql, Closure metaClosure, int offset, int maxRows, Closure rowClosure) 
    void eachRow(java.util.Map params, java.lang.String sql, int offset, int maxRows, Closure closure) 

這讓我疑惑:我在做什麼錯了,我該如何處理命名爲eachRow參數。

回答

2

eachRow方法,你指的是可用的,因爲Groovy的1.8.7:

http://groovy.codehaus.org/api/groovy/sql/Sql.html#eachRow(java.lang.String,%20java.util.Map,%20groovy.lang.Closure

我假設你之前使用1.8.7一個Groovy版本。

+0

不幸的是,Groovy版本:2.0.5 JVM:1.6.0_35供應商:Sun Microsystems Inc.操作系統:Windows XP – Kw4s

+0

有沒有可能在您的項目類路徑中存在另一個Groovy版本? –

+0

那麼,可能是這樣,因爲我使用Gradle,它似乎提供它自己的groovy – Kw4s