groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul King <pa...@asert.com.au>
Subject Re: Convert JDBC Result sets to xml
Date Sat, 30 Jul 2016 02:55:48 GMT
Do you want something like this?

def rows = [[ID:1, NAME:'Test1'], [ID:2, NAME:'Test2']]
def mb = new groovy.xml.MarkupBuilder()
mb.root {
  rows.each { next ->
    row {
      next.each { k, v ->
        "$k"(v)
      }
    }
  }
}


On Sat, Jul 30, 2016 at 3:43 AM, GroovyBeginner
<groovybeginner@gmail.com> wrote:
> 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