sql - Store DB columns values to string in Groovy -


i trying store sql query result string.

def dblist = con.rows("select a.pkresourceitemsid,b.fieldvalue,a.fkresourceid,a.fkcountryid,b.fklocationid,b.fkbusinessunitid,b.floor tblresourceitems inner join tblresourceitemdata b on a.pkresourceitemsid=b.fkresourceitemid a.pkresourceitemsid='$id'" )  log.info "db_list = ${dblist}" 

the result getting:

db_list =[[pkresourceitemsid:2000, fieldvalue:hello, fkresourceid:1, fkcountryid:1, fklocationid:88, fkbusinessunitid:518, floor:1]] 

the result want :

db_list =[2000, hello, 1, 1, 88, 518, 1] 

what have tried :

def = dblist.pkresourceitemsid 

it gives me result [2000], can 1 column @ time.

don't know how columns. how can achieve this?

sql.rows(gstring query) returns list<groovyrowresult> why when make println of returned object get:

[[pkresourceitemsid:2000, fieldvalue:hello, fkresourceid:1, fkcountryid:1, fklocationid:88, fkbusinessunitid:518, floor:1]] 

if instead of want list result values can perform follow operation on object returned sql.rows() method call as:

// each row in result list def rowresults = dblist.collect{ row ->     // column values     row.keyset().collect { row[it] } } 

this generic approach since rows() returns multiple results, you've list of lists each list contains values.

if you're interested in first result; first object in list:

println rowresults[0]  // [2000, hello, 1, 1, 88, 518, 1] 

approach: use firstrow instead

if query it's designed 1 result, use firstrow() instead of rows(), way you'll have directly groovyrowresult instead of list<groovyrowresult>, , can values without column names easily:

def dblist = con.firstrow("select a.pkresourceitemsid,b.fieldvalue,a.fkresourceid,a.fkcountryid,b.fklocationid,b.fkbusinessunitid,b.floor tblresourceitems inner join tblresourceitemdata b on a.pkresourceitemsid=b.fkresourceitemid a.pkresourceitemsid='$id'" )  def rowvalues = dblist.keyset().collect { dblist[it] } println rowvalues // [2000, hello, 1, 1, 88, 518, 1] 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -