(For more resources on JasperReports, see here.)
You will need PostgreSQL to follow this recipe. Refer to the installPostgreSQL.txt file included in the source code download (chap4), which shows how you will install and run PostgreSQL. Note that your installation of PostgreSQL should be up and running before you proceed.
The source code for this article also includes a file named CreateDbIntoPGS.txt, which will help you to create a database named jasperdb5.
How to do it…
The following simple steps will show you how to connect iReport to a database:
- Run iReport; it will open with a Welcome Window, as shown in the following screenshot:
- 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:
- 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.
- 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:
- You will see Database JDBC connection is selected by default. Click the Next button at the bottom of the Datasource window.
- A new window named Database JDBC connection will open, as shown in the following screenshot:
- Enter PG as the name for your new database connection in the input box beside the Name field.
PG is just a name for the database connection you are creating. You can give any name and create any number of database connections.
- 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: