Reputation: 301
I am trying to make a stream collect
on my SQL rowset within a groovy script, however the output is an empty array. Calling print within the closure works.
Any ideas on how I can processes all the rows without having to consume them in the first closure and without referencing out-of-scope variables?
import groovy.sql.Sql
def sql = Sql.newInstance("jdbc:mysql://localhost", "login", "password", "com.mysql.jdbc.Driver")
// Display databases
println "Databases: "
println sql.eachRow("SHOW databases") {row -> "${row[0]}"}.collect()
Any help much appreciated, thanks!
Upvotes: 1
Views: 1277