groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GroovyBeginner <groovybegin...@gmail.com>
Subject Convert JDBC Result sets to xml
Date Fri, 29 Jul 2016 17:43:52 GMT
Is there any approach of converting the JDBC result sets to xml dynamically
with out specifying the tags in xml as column names. I am using the
following code 

import groovy.sql.Sql; 
import java.sql.ResultSet;

Sql sql = Sql.newInstance("jdbc:oracle:thin:@localhost:1521:XE","username",
"password", "oracle.jdbc.driver.OracleDriver") 

StringBuilder builder = new StringBuilder()

sql.eachRow("select * FROM A") { row -> 
   builder.append( "${row}" )
} 

return builder.toString()

This code is returning result of lists a sample output would be [ID:1,
NAME:Test1][ID:2, NAME:Test2] Is there approach of getting this output as
<root><ID>1</ID><Name>Test1</Name><ID>2</ID><Name>Test2</Name></root>.
Any
help would be much appreciated



--
View this message in context: http://groovy.329449.n5.nabble.com/Convert-JDBC-Result-sets-to-xml-tp5734358.html
Sent from the Groovy Dev mailing list archive at Nabble.com.

Mime
View raw message