I am writing a JasperReports program where I want the query to be externalized to properties file.
I am injecting the query as string in my Java program.
In the jrxml file I have the following statements:
<parameter name="mySqlQuery" class="java.lang.String"/>
<queryString>
<![CDATA[$P{mySqlQuery}]]>
</queryString>
The Java program has the following:
hashmap.put("mySqlQuery", this.mySqlQuery);
JasperReport jasperReportMyClass = JasperCompileManager.compileReport(this.reportMyClass);
JasperPrint jasperPrintMyClass = JasperFillManager.fillReport(jasperReportMyClass, hashmap, con);
jprintList.add(jasperPrintMyClass);
Which I am then exporting to excel.
If I am hardcoding the same query directly in the JRXML queryString tags, it works fine.
Thanks for reading!
Yes, it is possible.
Try to use
$P!{mySqlQuery}expression instead of$P{mySqlQuery}in your jrxml file.You can read details here.