Fields in JasperReports

By: MakeItSimple. Viewed: 153256 times  Printer Friendly Format    


Report fields represent the only way to map data from the data source into the report generating routines. When the data source of the report is a ResultSet, all fields must map to corresponding columns in the ResultSet object. That is, they must have the same name as the columns they map and a compatible type.

For example:  

If we want to generate a report using data retrieved from the table Employees, which has the following structure:  

Column Name      Datatype       Length

--------------------------------------
EmployeeID       int             4
LastName         varchar        20
FirstName        varchar        10
HireDate         datetime        8

we can define the following fields in our report design:  

<field name="EmployeeID" class="java.lang.Integer"/>
<field name="LastName" class="java.lang.String"/>
<field name="FirstName" class="java.lang.String"/>
<field name="HireDate" class="java.util.Date"/>

If we declare a field that does not have a corresponding column in the ResultSet, an exception will be thrown at runtime. Columns present in the ResultSet object that do not have corresponding fields in the report design do not affect the report filling operations, but they also wont be accessible.



Most Viewed Articles (in Java )

Latest Articles (in Java)

Comment on this tutorial