Java Reference
In-Depth Information
<textFieldExpresson> has a single sub-element, which is the report expression that
will be displayed by the text field, wrapped in an XML CDATA block. In this example,
each text field is displaying the value of a field. Therefore, the expression inside
<textFieldExpression> uses the <field> syntax explained previously.
Compiling a report containing a query is no different from compiling a report
without a query. It can be done either programmatically or through the custom
JasperReports JRC ANT task. We covered compiling reports in Chapter 3.
Generating the Report
As mentioned previously, in JasperReports terminology, the action of generating
a report from a binary report template is called illing the report. To fill a report
containing an embedded database query, we must pass a database connection object
to the report. The following example illustrates this process:
package net.ensode.jasperbook;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
public class DbReportFill
Connection connection;
public void generateReport()
connection = DriverManager.getConnection ("jdbc:mysql://
System.out.println("Filling report...");
new HashMap(), connection);
Search WWH ::

Custom Search