Programming Tutorials

Fields in JasperReports

By: MakeItSimple. in Java Tutorials on 2008-09-02  

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.






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Java )

Latest Articles (in Java)