asperReports, a powerful, flexible open-source reporting engine, is easy to integrate into Java enterprise applications, but it lacks an integrated visual report editor. So, if you want to use JasperReports directly, you need to manipulate its XML report structurea relatively technical activity with a high learning curve, to say the least.
In fact, writing a full JasperReport from scratch using only the XML format is a long, painful, and unrewarding task.
Luckily, some available alternatives are much easier. The first and foremost of which is to use a visual editor to design, compile, and test your reports.
One of the most useful visual editors you can use is iReport. This article demonstrates how to use iReport to leverage the full power of JasperReports without getting entangled in complexities of the JasperReports native XML format.
The first thing to do is download and install iReport. It is a Java application, so you will need a JDK on your machine (JDK 1.4 or higher). This tutorial uses JDK 1.5.0:
- Download iReport from ireport.sourceforge.net.
- Decompress the iReport archive.
- Run the startup script (bin\startup.bat or ./bin/startup.sh).
The iReport download comes with its own JasperReports package (the latest version to date, 0.5.1, supports the recently released JasperReports 1.0.1).
|Figure 1. The Tutorial's Employee Database Schema|
Once you have iReport running, you can start designing your reports!
The Example Database
This tutorial uses a very simple database (see Figure 1
) for demonstration. To follow along step-by-step, either download the scripts
for setting up this database with MySQL and set it up on your machine, or use a similar database and translate the techniques to your situation.
Adding a New Database Connection
First, add a new connection to your database. Use the "Datasource -> Connections/Datasources" menu to set up a new database connection (see Figure 2
). If you chose the JDBC driver in the list (the example chooses MySQL), enter the server address and the database name, and then click on the 'Wizard' button. iReport should provide you with a correct JDBC URL for your particular database.
Now that you have a datasource, it's time to do something with it.