Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Open Source Java Reporting with JasperReports and iReport : Page 2

JasperReports is a powerful and flexible open source reporting solution. The iReport visual designer enables you to take advantage of the full power of JasperReports without in-depth knowledge of the JasperReports native XML format.


advertisement

Creating a Simple Report

Figure 3. A New JasperReports 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:

  1. 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.
  2. Page Header: This section appears at the top of each page—as you would expect. It is a good place for dates, page numbers, etc.
  3. Column Header: This section goes at the top of each column.
  4. Detail: This is where the information for each record entry is placed. JasperReports generates a detail section for each and every record it processes.
  5. Column Footer: This section goes at the bottom of each column.
  6. Page Footer: This section appears at the bottom of each page.
  7. Last Page Footer: This section goes at the bottom of the last page.
  8. Summary: This section appears right at the end of the report, just after the last record.



Figure 4. The Report Query

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

Figure 5. Report Fields

Report Fields
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).

Figure 6. Laying Out Report Fields

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.

Figure 7. Preview Report Results

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.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap