Skip to main content

Post 7: iReport: Creating a report from relational data


Creating a report from relational data
This post shows how you will connect JasperReports to your database. I am using an open source database named PostgreSQL to hold the sample data of almost all post of iReport.
This post also shows that you can connect iReport to any of the popular databases in a similar manner
Getting ready
You will need PostgreSQL to follow to Post 6: iReport: Installation of PostgreSQL which shows how you will install and run PostgreSQL. Note that your installation of PostgreSQL should be up and running before you proceed.

Create a database
You need to follow the procedure described below to create a database instance.

Run SQL Shell
1) Click PostgreSQL 9.3 -> SQL Shell (psql), from Programs menu of your Windows installation, to run SQL Shell for PostgreSQL server
 

2) You will see SQL Shell consol window. SQL Shell window will prompt you for server location, database, port and username, press Enter for each prompt.
You will be logged to postgres database.

 



Create Database instance
Copy following SQL command in SQL shell to create a database instance.
-> CREATE DATABASE jasperdb5;

 


Your jasperdb5 database instance will be created.
Now follow the steps in next section to copy data in the jasperdb5 database.

How to do it...
The following simple steps will show you how to connect iReport to a database:
1. Run iReport; it will open with a Welcome Window, as shown in the following screenshot:

 

2. If you have not made any database connection so far in your iReport installation, you will see an Empty datasource shown selected in a drop-down list just below the main menu. Click on the Report Datasources icon shown encircled to the right of the drop-down list, as shown in the following screenshot:
 
3. A new window named Connections / Datasources will open, as shown in the following screenshot. This window lists an Empty datasource as well as the datasources you have made so far.

 

4. Click the New button shown at the top right of the Connections / Datasources window. This will open a new Datasource selection window, as shown in the following screenshot.
 
 

5. You will see Database JDBC connection is selected by default. Click the Next button at the bottom of the Datasource window.

6. A new window named Database JDBC connection will open, as shown in the following screenshot:



7. Enter PG as the name for your new database connection in the input box beside the Name field.
Note: PG is just a name for the database connection you are creating. You can give any name and create any number of database connections
8. suppose by default  Postgres is not selected then click on the JDBC Driver drop-down list; it will drop-down to show a list of available JDBC drivers. As you are connecting to the PostgreSQL database, select the Postgre SQL (org.postgresql.Driver) option from the drop-down list, as shown in the following screenshot:
 
 

10 update the JDBC URL field, as shown in the following screenshot:

11 Provide postgres as the value of the Username and Password (root in our case) fields, as shown in the following screenshot
 


12. Check the Save password checkbox beside the Password field shown in step 11 to save your database password permanently for reports generated using iReport.

13. Click the Test button to test the new database connection. In the case of a successful connection, you will see a Connection test successful message in a dialog window. Dismiss the message by clicking the OK button.

 

14. Click the Save button to save the newly created connection. You will see that the Connections / Datasources window will open showing your new connection set as the default connection in the connections list, as shown in the following screenshot:

 

And click on close.
15. Now you are all set to generate a report from the data contained in your PostgreSQL installation. Whenever you are opening or viewing a report based on data contained in PostgreSQL, just make sure that PG is selected in the datasources drop-down list, as shown in the following screenshot:

 
There's more...
You have learned how to connect iReport to PostgreSQL. If you have some other database, you just need to select the appropriate JDBC driver from the JDBC Driver drop-down list in step 8 of the recipe.
iReport comes bundled with drivers for the following open source databases:
MySQL
PostgreSQL
HSQLDB
If you are not using an open source database, you will need to separately download and install the relevant JDBC drivers.
 
 
 

Comments

Popular posts from this blog

TIME TABLE: VTU BE/B.Tech June/July 2016 Exam Time table Draft Layout

Semester-wise June-July 2016 Exam time table (Draft Layout) Are You Using updated Kwikstudy App?

Walkins Bangalore: 01st-Oct-2016

1. UTC Aerospace : GET – S&IS-Software Team hiring Electronics & CSE / IT Freshers ! Walkin on 1st OCT | BE/BTECH - 2015 & 2016 both batch can try Selection Process : Written Test Group Discussion Technical & HR Interviews How To Apply : It is a walk-in drive for 2016 batch eligible freshers on 1 Oct 2016 at Bangalore location. Interested and eligible candidates can walk-in to the following venue on 1 Oct 2016 Date of Drive : 01 Oct 2016 Reporting Time : 8:00 AM to 11:30 AM Venue : UTC Aerospace Systems – Site 1, Sy. Nos. 14/1 & 15/1, Maruthi Industrial State, Phase 2, Hoody Village, Whitefield Road, K R Puram Hobli, Bangalore – 560048 ______________________________________ 2. HP : Software Eng/ Software Tester (Call based ,less chance of getting entry , try at your own risk) Event Date : 1-October-2016 Event Time : 8 : 00 am Job Location : Bangalore / Chennai Job Description: Software Engineer /

How to get VTU Provisional Degree Certificate (PDC) ?

Here is the procedure to get the Provisional Degree Certificate from the VTU by passed out candidates. You can get the certificate through post by sending the required documents to VTU. Documents and things required: 1. Provisional Degree Certificate (PDC) application form 2. DD of specified fees amount or print copy of receipt if you paid the fees online 3. A letter to the VTU registrar 4. A4 size envelope Step 1: Fill the PDC application You can download the PDC application form from the VTU website. Click below link for application download. PDC application form download     After downloading the application take a print of it and properly fill the form. Step 2: Make a DD of specified amount as the fees of PDC: Go to the bank and make the DD of prescribed fee amount for the PDC. The fee amount is specified in the above link from where you downloaded the application. Make the DD in favor of " Finance Officer, VTU Belgaum ".   Wr