2013-07-01 2 views
-1

아래 코드는 SQL의 각 행에 대한 권한을 부여합니다. SQL 쓰기가 끝날 때 한 줄만 쓸 수있는 방법이 있습니까? 그 구문은 무엇입니까? '이 보고서는 2013 년 7 월 1 일 사용자 John Doe에 의해 실행되었습니다.'와 유사합니다.GROOVY sql write 끝에 다른 줄을 작성하십시오.

db.eachRow(sql) { 
    def desc = it.summary 
    desc = desc.replaceAll("[\r\n]", "") 
    file.append(it.CHANGEID + "\t" + it.REGION + "\t" + it.DIVISION + "\t" + desc + "\t" + "\n") 
    } 
+0

'isLast'부터 [GroovyResultSet] (http://groovy.codehaus.org/api/groovy/sql/GroovyResultSet.html)이 충분해야 의미 ? – dmahapatro

답변

1
db.eachRow(sql) { 
    .... 
    if(it.isLast()){ 
    //Append custom text to file. 
    } 
} 
1

는 당신이 바로

String user = 'tim' // for example 

new File('output.txt').withWriter { w -> 
    db.eachRow(sql) { 
    def desc = it.summary 
    desc = desc.replaceAll("[\r\n]", "") 
    w.writeLine("$it.CHANGEID\t$it.REGION\t$it.DIVISION\t$desc") 
    } 
    w.writeLine("written by $user on ${new Date()}") 
} 
관련 문제