Creating a Simple Report
Create a new JasperReports document using the "File/New Document" menu entry. You can ignore all the various options for now. Just give the report a name. You will get an empty report, as shown in Figure 3.
A JasperReport report is divided into the following display sections, illustrated in the iReport screen:
- Title: As the name indicates, this section contains the report title. It is generated only once and appears only at the very start of the report.
- Page Header: This section appears at the top of each pageas you would expect. It is a good place for dates, page numbers, etc.
- Column Header: This section goes at the top of each column.
- Detail: This is where the information for each record entry is placed. JasperReports generates a detail section for each and every record it processes.
- Column Footer: This section goes at the bottom of each column.
- Page Footer: This section appears at the bottom of each page.
- Last Page Footer: This section goes at the bottom of the last page.
- Summary: This section appears right at the end of the report, just after the last record.
First, specify an appropriate SQL query for your report, using the Datasource/Report Query menu (see Figure 4). The query will request a list of all the employees in the database:
select * from employee e, service s
where e.serv_id = s.serv_id
order by s.serv_name, e.emp_surname, e.emp_firstname
Each JasperReports report has a list of fields, which are used to place data records coming from the database query in the report layout.
You can visualize the field list using the "View/Report Fields" menu (see Figure 5).
When you create a SQL query, this list automatically updates with the fields your query returns. In cases in which you use other types of datasources, you may have to define the fields by hand.
From the report fields window, you can drag and drop fields onto your report. Fields usually go into the Detail section, as Figure 6 illustrates. Place three fields into the Detail section, along with appropriate column titles in the Column Header section. The column titles are static text items, which you can insert by using either the "T" icon or the "Insert Element/Static Text" menu item. Play around with the formatting and layout options to become familiar with what iReport has to offer in this domain.
To test the whole thing, run the report using the "Build/Execute Report (using active conn.)" menu item. You should get something like the report in Figure 7.