JasperReport Tutorial for Beginners

1- Introduction

The document is based on:
  • Eclipse 4.4 (LUNA)

  • JasperSoft Studio (5.6.2)

2- The installation requires

Jaspersoft Studio Plugin:

To program  Jasperreport report you need to install JasperSoft Studio on Eclipse. You can see the instructions at:

Database LearningSQL

LearningSQL is a small database, used in many guidelines of o7planning. 
Programming Guide of  JasperReport also use the data on this Database. You need to create this Database (only 5 minutes)  as the instructions below:

Database driver library (Oracle, MySQL, SQLServer) and usage: 

Depending on which Database you use, you need that Database driver library (You need 3 minutes to complete), see the instructions for download at:

3- Reporting interface will design

This is the raw data:
On the report, we group it to get a result as the following illustration:
And here is the reporting interface:
Select Acc.Open_Branch_Id
     ,Bra.Name           Branch_Name
     ,Cus.Address        Cust_Address
From   Account  Acc
     ,Customer Cus
     ,Branch   Bra
Where  Acc.Cust_Id = Cus.Cust_Id
And    Acc.Open_Branch_Id = Bra.Branch_Id

4- Create JasperReport Project

Open Perspective: Report Design.
Next, create project HelloJasperReport:
  • File/New/Other..
Enter the name of the Project:
  • HelloJasperReport
Project has been created:

5- Create Data Adaptor

Here I connect with Oracle database. You can do the same with  MySQL or  SQLServer. There is some differences in the using library and  URL Connection String.
For Oracle, Enter:
  • JDBC Url: jdbc:oracle:thin:@localhost:1521:db11g
Error emerges when you do not declare the classpath of Database Library Driver.
Just Add the jar file location, the JDBC Driver library for this database
OK, Data Adaptor was created.

6- Design report

6.1- Create a new report

  • File/New/Other...
Enter the name of the report:
  • FirstJasperReport
Select Acc.Open_Branch_Id
      ,Bra.Name           Branch_Name
      ,Cus.Address        Cust_Address
From   Account  Acc
      ,Customer Cus
      ,Branch   Bra
Where  Acc.Cust_Id = Cus.Cust_Id
And    Acc.Open_Branch_Id = Bra.Branch_Id
The report is generated.
View Outline is very important. We often have to use it while designing a report.
A blank report page is created. In which, parts of content of  Page HeaderColumn Header, Column FooterPage Footer are repeatedly displayed on each page of the report. You can delete unnecessary parts of content by right-click on it and click Delete.
Here I deleted all of parts, except for  Column Header &  Detail in order to make it easy to design. We can recreate them if necessary.

Column Header: contains titles of data columns. It is duplicated in all pages by default.
Detail: contains records. It repeat numbers of records.

6.2- Rough design report

Drag and drop Rectangle object from Pallete to Column Header of the report. Then, fully spread out the width of Rectangle.
Next, adjust the height of Column Header so that it is equal to the height of newly-made Rectangle. The purpose is to erase unnecessary space in the report.
Change the background color of the rectangle:
Next, we create 2 groups in turn:
  • Group Branch
  • Group Cust
Their meaning is described in the following illustrative image:
On the Outline, right click to FirstJasperReport, select Create Group:
Next, we drag a Rectangle from Pallete to  "Branch Group Header 1" area.
Change the background color for the rectangle you just created.
Next, we will drag drop respectively the Field Open_Branch_Id and Branch_Name into Rectangle on the block "Branch Group Header 1".
Similarly, we drag and drop  Branch_Name next to  Open_Branch_Id.

Next, Create Customer group:

After  Customer Group is created, drag and drop Rectangle object into  "Customer Group Header 1". Adjust and change background of Rectangle as the following illustrative image:
Drag & drop Field: Cust_ID into Rectangle just created.
Similarly, drag & drop Cust_Address field.
Next, drag and drop fields  Account_IdProduct_CdAvail_Balance into  "Detail 1" area in turn:
Note: If you drag and drop FIELDS into Detail area, column titles will be automatically created in  Column Header area.
Adjust the height of  "Detail 1" area to a minimum:
Next, drag and drop the remaining column titles:
Minimize the height of 2 areas:
  • Customer Group Footer 1
  • Branch Group Footer 1
Next drag & drop Field: AVAIL_BALANCE into "Customer Group Footer 1" & "Branch Group Footer 1".
Simultaneously, we change background of two objects we have just dragged and dropped.

6.3- Run report (First time)

We test the report by clicking Preview TAB:

6.4- Beauty Report

Selecting the fields, and setting properties as shown below.

6.5- Run Report (Second time)

6.6- Design Header section of the report

Create images folder in project, copy file bank.png to this folder, as illustrated below:
  • bank.png
Drag and drop Image object from the Palette to the page header.
Next drag & drop "Static Text" object to Page Header.
Similarly, drag & drop second "Static Text" object to Page Header.

6.7- Run Report (Third time)

7- Calling JasperReport from Java Application

See tutorial at: