Java Reference
In-Depth Information
Although not directly related to database reporting, one more thing worth
mentioning is that we used the <pageHeader> element of the JRXML template for
laying out the report labels. If our report had more than one page, these labels would
have appeared at the top of every page.
Modifying a Report Query via Report Parameters
Embedding a database query into a report template is the simplest way to generate
a database report. However, it is not very flexible. If we need to modify the report
query, it is also necessary to modify the report's JRXML template.
The sample JRXML template, discussed in the previous section, generates a report
that displays all aircraft in the database with a horsepower equal to or greater than
1000. If we wanted to generate a report to display all aircraft with a horsepower
greater than or equal to 750, we would have to modify the JRXML and recompile
it. That's a lot of work for such a small change. Fortunately, JasperReports allows
us to modify an embedded database query easily, by using report parameters.
The following JRXML template is a new version of the one we saw in the previous
section, modified to take advantage of report parameters.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN"
<jasperReport name="DbReportParam">
<parameter name="hp" class="java.lang.Integer"/>
<![CDATA[select a.tail_num,
am.model as aircraft_model,
ae.model as engine_model
from aircraft a,
aircraft_models am,
aircraft_engines ae
where a.aircraft_engine_code in (
select aircraft_engine_code
from aircraft_engines
where horsepower >= $P{hp})
and am.aircraft_model_code = a.aircraft_model_code
and ae.aircraft_engine_code = a.aircraft_engine_code]]>
<field name="tail_num" class="java.lang.String"/>
<field name="aircraft_serial" class="java.lang.String"/>
<field name="aircraft_model" class="java.lang.String"/>
<field name="engine_model" class="java.lang.String"/>
Search WWH ::

Custom Search