Groovy convert sql.eachRow results to List

1.9k Views Asked by At
def List_Sftp = sql.eachRow(SftpQuery){ row ->
    if(row[4]=="SFTP")  {
        def names= row.collect{ "${row[0]},${row[1]} ${row[3]} ,${row[4]},${row[5]},${row[6]},${row[7]}" }
        println names
    }

    if(row[4]=="ROSETTANET"){
        def names= row.collect{ "${row[0]},${row[1]},${row[2]},${row[4]},${row[5]},${row[6]},${row[7]}" }
        println names
    }

}

Output above code is

[2.01.00,SAMSUNG,123,XYZ,7C7,file1.xml,zzzz]
[2.01.00,SAMSUNG,123,XYZ,7C7,file2.xml,yyyy]

I can't iterate this out as a list. Suggest how to convert this output to

[2.01.00,SAMSUNG,123,XYZ,7C7,file1.xml,zzzz,2.01.00,SAMSUNG,123,XYZ,7C7,file2.xml,yyyy]
1

There are 1 best solutions below

3
On
def all = []
sql.eachRow(SftpQuery){ row ->
   all.addAll row
}

println all

In all you will have all results in a single iterateble list