There are two ways to generate database reports. It can either be done by embedding SQL queries into the JRXML report template, or by passing data from the database to the compiled report via a datasource. We will discuss both of these techniques.
We will first create the report by embedding the query into the JRXML template. We will then generate the same report by passing it a datasource containing the database data.
JasperReports allows us to embed database queries into a report template. This can be achieved by using the<queryString>
element of the JRXML file. The following example demonstrates this technique:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="DbReport">
<queryString>
<!
[CDATA...