简体   繁体   English

Groovy SQL中Groovy闭包的用法

[英]Usage of Groovy Closure in Groovy SQL

I'm new in Groovy and kinda confused in using Groovy closures. 我是Groovy的新手,在使用Groovy闭包时有点困惑。

I'm inserting into a table while using Sql.execute(gstring, Closure) and get this error 我正在使用Sql.execute(gstring,Closure)插入表中并出现此错误

Caught: java.sql.SQLException: Incorrect number of parameters for processResults Closure
java.sql.SQLException: Incorrect number of parameters for processResults Closure

Here is my implementation: 这是我的实现:

sql.execute(insertPaymethodMethodByPaymentSourceId) { row ->
        println "$row.id"
    }

I'm using this function to use the new id for another function. 我正在使用此功能将新ID用于另一个功能。

Thank you! 谢谢!

Because there should be 2 params for this closure according to doc: 因为根据doc,此关闭应该有2个参数:

http://docs.groovy-lang.org/latest/html/api/groovy/sql/Sql.html#execute(groovy.lang.GString,groovy.lang.Closure) http://docs.groovy-lang.org/latest/html/api/groovy/sql/Sql.html#execute(groovy.lang.GString,groovy.lang.Closure)

processResults - a Closure which will be passed two parameters: either true plus a list of GroovyRowResult values derived from statement.getResultSet() or false plus the update count from statement.getUpdateCount(). processResults-一个闭包,将传递两个参数:true以及从statement.getResultSet()派生的GroovyRowResult值列表,或者为false加上statement.getUpdateCount()的更新计数。 The closure will be called for each result produced from executing the SQL. 对于执行SQL产生的每个结果,将调用该闭包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM