I'm loading the jasper reports file from .jasper file to improve the performance as below.
JasperReport rpt = (JasperReport)JRLoader.loadObjectFromFile(location);
but I have a requirement now, that a query which is formed dynamically has to be set to .jasper (compiled) file. is there a way to do the same?
Something like this?
Java
JasperReport rpt = (JasperReport)JRLoader.loadObject(Your .jasper file path);
Map paramMap = new HashMap();
paramMap.put("p_sql", "select * from baztable where foo='bar' and fuga='hoge' order by username");
// pass the dynamic query to .jasper file.
JasperPrint print = JasperFillManager.fillReport(rpt, paramMap, connection);
jrxml
<parameter name="p_sql" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["select * from baztable order by username"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[$P!{p_sql}]]>
</queryString>
You can use the $P! (Parameter with exclamation) which can be used for conditional queries. Using this you can craft dynamic queries based on certain conditions. A guide for the same can be found here.
This is a hack method for the JRXML file. The JRXML file has your query. You can write a Java code or any other code to replace/write down your Query here:
Sample MongoDB Query:
<queryString language="MongoDbQuery">
{'collectionName':'customer'}
</queryString>`
只需在 ireport 中打开 .jasper 文件,您就可以加载 .jasper 文件并对其进行编辑。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.