【Groovy】sql查找结果数据输到出XML

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

import groovy.sql.Sql
import groovy.xml.MarkupBuilder
def schema = "PROD"
def sql = Sql.newInstance("jdbc:oracle:thin:@hostname:1526:${schema}", 
      "scott", "tiger", "oracle.jdbc.driver.OracleDriver")
 
/* Request */
def req = """
SELECT id,  name, givenname, unit FROM ${schema}.people
WHERE
in_unit=1
AND visible=0
"""
def out = new File('out.xml')
def writer = new FileWriter( out )
def xml = new MarkupBuilder( writer )
 
xml.agents {
    sql.eachRow( req as String  ) {
        /* For each row output detail */
        row ->
            xml.agent(id:row.id) {
                name( row.name )
                givenname( row.givenname )
                unit( row.unit )
                }
    }
}