Java Reference
In-Depth Information
<![CDATA[$F{engine_model}]]>
</textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
The procedure for compiling a database report, by using JRResultSetDataSource ,
is no different from what we have already seen. To fill the report, we need to execute
a database query in our Java code, and pass the query results to the report in a
datasource, as can be seen in the following example:
package net.ensode.jasperbook;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperFillManager;
public class DbReportDSFill
{
Connection connection;
Statement statement;
ResultSet resultSet;
public void generateReport()
{
try
{
String query = "select a.tail_num, a.aircraft_serial, "
+ "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 >= 1000) and am.aircraft_model_code =
a.aircraft_model_code "
 
Search WWH ::




Custom Search