Below script, outputs all in 1 single row. Is there a way to output in separate row ?
import com.atlassian.jira.component.ComponentAccessor
import groovy.sql.Sql
import org.ofbiz.core.entity.ConnectionFactory
import org.ofbiz.core.entity.DelegatorInterface
import java.sql.Connection
def 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.eachRow("select top 5 * from jiraissue") {
sb << "${it}"
}
sb.toString()
return sb
} finally {
sql.close()
}
You can use something like this:
import com.atlassian.jira.component.ComponentAccessor
import groovy.sql.Sql
import org.ofbiz.core.entity.ConnectionFactory
import org.ofbiz.core.entity.DelegatorInterface
import java.sql.Connection
def 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.eachRow("SELECT * FROM JIRAISSUE WHERE ROWNUM <= 10") {
sb << "${it}"
sb<<(System.getProperty("line.separator")) //this will add the new lines
}
sb.toString()
log.warn(sb) //this line will append it under the "log" section
return sb
} finally {
sql.close()
}
