Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to extract id value from sql query using groovy

Vineela Durbha
Contributor
May 24, 2019

I am trying to run groovy script to extract ID from jira db

Connection conn = ConnectionFactory.getConnection(helperName);
log.debug("connection succees")

Sql sql = new Sql(conn)
def row;
StringBuffer sb = new StringBuffer()

try {
sql.eachRow("""select ji.id as 'ID' from jiraissue ji
left join project p with(nolock)
on ji.project = p.id
where p.pkey='SWRM' and ji.summary='19.10'""") {
//log.warn("${it}")
sb << "${it}"

}
sb.toString()
log.debug("sb value " +sb)
return sb
} finally {
sql.close()
}

 

sb is returning [ID:873319], but i just want to extract 873319 so that I can pass it to another field.

1 answer

0 votes
Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 24, 2019

You could use the substring function to remove the first 4 and last characters.

sb.substring(4,sb.length()-1)

Suggest an answer

Log in or Sign up to answer