You can certainly put them both into the same report.
You'll need to run the SQL query twice.† Putting your summary report into the summary band of your detailed report as a subreport will be the simplest solution. You'll use the same SQL connection, then the subreport will run its own query (which just happens to be identical to the query in the main report).
Alternative solutions include:
One main report that is nearly empty which holds two subreports. This can be a good solution for complex reports. But given your requirements, it creates a bit more work without any benefit.
Using a Table component (or List component) in the summary band rather than a subreport. I generally prefer this. If you didn't already have the two reports created, I would probably recommend this. But re-writing your report as a table component would again be additional work with no real benefit.
† That's not a fundamental requirement. If you decided that the SQL query is tremendously long-running and not further tune-able, then it would surely be possible to do everything in a single pass through the result set. It would just require extra cleverness to capture all of the information that you need in that single iteration and then display it in the summary. It would be significantly more work than the other variations.
You can use the expression like this: SELECT .. FROM .. WHERE strAttr=$P{strFilter}
in jrxml file.
The snippet from the report's template (jrxml file):
<parameter name="strFilter" class="java.lang.String"/>
<queryString>
<![CDATA[SELECT city FROM address WHERE city=$P{strFilter}]]>
</queryString>
<field name="city" class="java.lang.String"/>
This code works fine for strings with single quotation, double quotation and parenthesis symbols:
Map<String, Object> params = new HashMap<String, Object>();
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
//params.put("strFilter", "Berl)in");
//params.put("strFilter", "Muni\"ch");
params.put("strFilter", "Stuttga'rt");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, connection);
JasperExportManager.exportReportToPdfFile(jasperPrint, pdfFileName);
Or you can use the expression like this: SELECT .. FROM .. WHERE $P!{whereClause}
.
The snippet from the report's template (jrxml file):
<parameter name="strFilter" class="java.lang.String"/>
<parameter name="whereClause" class="java.lang.String"/>
<queryString>
<![CDATA[SELECT city FROM address WHERE city=$P{strFilter} $P!{whereClause}]]>
</queryString>
This code works fine for strings with single quotation, double quotation and parenthesis symbols:
Map<String, Object> params = new HashMap<String, Object>();
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
//params.put("strFilter", "Berl)in");
//params.put("whereClause", "AND city = 'Berl)in'");
//params.put("strFilter", "Muni\"ch");
//params.put("whereClause", "AND city = 'Muni\"ch'");
params.put("strFilter", "Stuttga'rt");
params.put("whereClause", "AND city = 'Stuttga''rt'");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, connection);
JasperExportManager.exportReportToPdfFile(jasperPrint, pdfFileName);
Best Answer
iReport is a graphical tool for creating jasper reports.
It will generate the xml jasper report file for you.
Or to quote iReport:
After you create your file you will have to learn a small bit about Jasper report to integrate it into your program.
For more information have a look at this iReport introduction page.