Hello,
As I understand, you have a Groovy data band in a report, and you want to execute an SQL query within that Groovy code.
How about making a service to execute that SQL via EntityManager, and then call it inside the code? It works, I call the BPM engine api inside my reports…
Also, try this one (not sure if it will work, will try tomorrow):
import org.springframework.jdbc.core.JdbcTemplate
def jdbcTemplate = applicationContext.getBean(JdbcTemplate)
// Access report parameters via 'params' map
def startDate = params['startDate'].value
def endDate = params['endDate'].value
def statusParam = params['status'].value
def rows = jdbcTemplate.queryForList("""
SELECT
id,
name,
created_date,
amount
FROM orders
WHERE created_date BETWEEN ? AND ?
AND status = ?
ORDER BY created_date
""", startDate, endDate, statusParam)
return rows
If it works, add logic to test params for nulls if needed.
Kind regards,
Mladen