Following tutorial should give you a short overview how to create reports using JasperReports. Will discuss infrastructure, editor and guide you through basic steps to create, deploy and run reports.
Discover the tools
While creating a report you need several tools. First of all, you must have a SQL query created. Using DbVisualizer or SQL*Plus console for Oracle you may develop a query which will extract data necessary for the report. It is absolutely right to tune the query outside the report engine. If you are ready to create a report, you have to use a iReport editor - download iReport Classic 3.0.0 (not any other version) from the project page. Using this WYSIWYG report editor you can create and deploy a report. To deploy a report, you need to know where to find or install on your own an instance of JasperServer and have administrator access into it.
Authoring the report in iReport
In order to create a report, open the iReport and select File > New Document. Here you can give your report a name and select page format. It is better to use landscape page format in case you will have a lot of columns and want to have all in one row. Let's start... We have created a new document. We will use a dummy SQL query to get some report data:
SELECT 1 AS DATA_ID, 'A name' AS DATA_NAME
FROM dual
Using Data > Report Query menu you can add the query into report. The report requires to specify a field for any row retrieved from the query. You can add fields using View > View Field dialog, or in the Document Structure explorer where right-clicking on Fields and selecting Add > Field you can start to specify one new field. The Field Name must conform to column name in the query, e.g. DATA_ID and DATA_NAME in our example. Consider the best Field Class Type for the field value. Of course, a Description is optional.
When you setup the source query and define field which map to columns in the result dataset, you can put the fields into the report. Drug'n'drop them from the Document Structure explorer into the detail part in the report. To define some column headers, use F icon for Static Text, draw a text field, fill in the text and you may format the text as well.
Don't forget to save your report as a temporal file before we deploy it, e.g. to /tmp or so.
Deploying and running a report
JasperServer is an environment implemented on top of Apache Tomcat container which hosts, manages and runs reports. You can manage the server using JS plugin 3.0 inside the iReport editor. You just need have administrator account. After you setup JasperServer connection and log in, you may deploy your newly created report. We will work in the /Tutorial folder of the internal JS structure.
Right-click on the Tutorial folder and select Add > Report Unit, a dialogue will be shown. Fill in a Name and a Label, and move to next step. Here you define the JRXML template file. You can select anyone deployed in the JasperServer but we will select the file that we have created previously and which we have opened in the iReport. We will select Locally Defined and using Get source from current opened report button we fill the path of the opened report. Last step requires to select a Data Source. We suppose to have one defined in the JasperServer. Thus we select From the repository and find the appropriate one in the select. For this dummy report it does not matter which one in case it works. Finish the dialogue and you have the report deployed.
Now we are going to run the report and get result. You need to login into the JasperServer using your preferred browser. Now navigate using the Folders tree explorer into the folder /Tutorial. Here you can find your Dummy Report. Clicking on report name you run the generating and the result is shown on the screen. You are able to download the report in various formats such as PDF, XLS or RTF.
How to edit a deployed report
If you have the report opened in the iReport, you just make the changes and save. Otherwise you need to double-click to the report in JS plugin which will result into expanding the structure, right click on Main.jrxml and select Edit JRXML. The template file will download and open in iReport. After you have changes done and save, right click on report in JS plugin, select Properties, Main Report and Data Sources, in Locally Defined fill the text field using Current Report button and Save Report Unit. After that you can see in JasperServer that the report changed.