问题
def colarray=[]
def num
def newRole = rolecol.split(',')
def len = newRole.size()
println "$newRole,$len"
for (num = 0; num < len; num++) {
def col = "col"
col="$col"+newRole[num]
colarray.add(col)
}
println colarray
sql.eachRow("select col01,$colarray from read_csv where col01=? and col${usercol}!=? ", [file.name,""])
i want save col1..col11 into array and call it from select statement, but the problem is that $colarray has the brackets with it (like [col03, col04, col05, col06, col07, col08, col09, col10, col11, col12, col13, col14, col15, col16, col17, col18, col19, col20, col21, col22, col23, col24, col25, col26, col27, col28, col29, col30, col31, col32, col33] ), so now i want to remove them, anyone can help with it???thx
回答1:
the []
are there, because you are doing an implicit toString
on the list. use colarray.join(',')
回答2:
def colarray = rolecol.tokenize(',').collect { "col$it" }.join(', ')
Then you will also need to escape your sql:
sql.eachRow("select col01, ${Sql.expand(colarray)} from read_csv where col01 = ? and ${Sql.expand('col' + usercol)} != ? ", [file.name,""])
来源:https://stackoverflow.com/questions/28064184/groovy-array-remove-the-brackets