2015-01-21 84 views
-2
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,""]) 

我想保存col1..col11到數組,並從select語句調用它,但問題是,$ colarray有它的括號(如[col03,col04,col05,col06, col0,col10,col09,col10,col11,col12,col13,col14,col15,col16,col17,col18,col19,col20,col21,col22,col23,col24,col25,col26,col27,col28,col29,col30,col31,所以現在我想刪除它們,任何人都可以幫助它??? thx常規陣列中的括號去掉

回答

0

[]在那裏,因爲你正在做一個隱含的toString在列表上。使用colarray.join(',')

+0

感謝會嘗試 – 2015-01-21 10:10:54

+0

高清AA = colarray.join( '') 的println AA // sql.eachRow( 「選擇COL01,從read_csv其中COL01 =?和col $ {} usercol!=?$ AA」,[file.name 「」]) 您好我編輯它這樣,但得到錯誤,請查看下面的註釋 – 2015-01-21 10:14:22

0
def colarray = rolecol.tokenize(',').collect { "col$it" }.join(', ') 

然後你還需要逃避你的SQL:

sql.eachRow("select col01, ${Sql.expand(colarray)} from read_csv where col01 = ? and ${Sql.expand('col' + usercol)} != ? ", [file.name,""]) 
+0

THX會試試吧.. – 2015-01-21 10:11:50

+0

嗨我試過了,但得到與我的代碼相同的錯誤信息..請檢查我的答案..如果你可以再幫助thx – 2015-01-21 10:16:34