I am trying to display sql query results as below
sql.eachRow(select * from issue){row->// log.error("loggggg" +row.values().toString());
}
But it is not displaying results. Am i doing something wrong?
can someone help on this
Hello Vineela,
The name of the table should be jiraissue.
Even i tried with jiraissue .but no use
How is your whole code?
it should be "select * from jiraissue" with quotes.
Yah it is "select * from jiraissue" with quotes
try {sql = new Sql(conn);
def sqlQueryREC ="select * from jiraissue";
sql.eachRow(sqlQueryREC )
{row->
log.error("results")
Nothing is being printed from that log.error. Is my sql.eachRow method syntax correct?
If so how should i display all the rows and what is the syntax for it?
log.error("results") only logs results string if that's the one you see in logs.
However, if you do not see anything in the log file, just go to script console and try below code, you should see all issues in console, but jiraissue table may contain lots of issues so trying with another table should be wise (like issuestatus)
Try this one for jiraissue
import com.atlassian.jira.component.ComponentAccessorimport groovy.sql.Sqlimport org.ofbiz.core.entity.ConnectionFactoryimport org.ofbiz.core.entity.DelegatorInterfaceimport java.sql.Connectiondef delegator = (DelegatorInterface) ComponentAccessor.getComponent(DelegatorInterface)String helperName = delegator.getGroupHelperName("default");Connection conn = ConnectionFactory.getConnection(helperName);Sql sql = new Sql(conn)StringBuffer sb = new StringBuffer()try { sql = new Sql(conn); sql.eachRow("select * from jiraissue") { log.warn("${it}") sb << "$it.id $it.summary" } return sb} finally { sql.close()}
And also please bear in mind that there is a loop here, so it might not have single result. In my code, I was concatenating all id values into stringbuilder.
It looks like you're new here. Sign in or register to get started.