passing a “where condition” to jasperreports exporting pdf

北战南征 提交于 2019-12-25 03:29:18

问题


A simple SQL table, with two attributes and three rows:

reference | name:

0 | first

1 | second

2 | third

I have a Java application, with Swing, showing this through a JList (each row concatenates the two strings, reference and name).

I push a button, I export the entire database successfully, using my "from_ireport.jasper", compiled from iReport. I can compile from code too.

I want to select one or more elements, push the button and get a pdf with just the selected elements. Where and how do I specify the "where condition" to jasper?

I can't find a easy example to look at. Thanks.


回答1:


For solving this issue you can use the JR report's parameters.

For example you can use this query expression:

<queryString>
        <![CDATA[SELECT reference, name FROM table WHERE $P!{whereCondition}]]>
</queryString>

The sample of Java code for passing parameter's value:

Map<String, Object> params = new HashMap<String, Object>();
params.put("whereCondition", "reference > 0");
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, connection);

For more details you can view Query Sample.



来源:https://stackoverflow.com/questions/12081601/passing-a-where-condition-to-jasperreports-exporting-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!