iReport in NetBeans

iReport 3.7


April 2010

$23.99

Learn how to use iReport to create, design, format, and export reports

Creating different types of reports inside the NetBeans IDE

The first step is to download the NetBeans IDE and the iReport plugin for this. The iReport plugin for NetBeans is available for free download at the following locations: https://sourceforge.net/projects/ireport/files or http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=4425

After downloading the plugin, follow the listed steps to install the plugin in NetBeans:

  1. Start the NetBeans IDE.
  2. Go to Tools | Plugins.
  3. Select the Downloaded tab.
  4. Press Add Plugins….
  5. iReport 3.7

  6. Select the plugin files. For iReport 3.7.0 the plugins are: iReport-3.7.0.nbm, jasperreports-components-plugin-3.7.0.nbm, jasperreportsextensions-plugin-3.7.0.nbm, and jasperserver-plugin-3.7.0.nbm. After opening the plugin files you will see the following screen:
  7. iReport 3.7

  8. Check the Install checkbox of ireport-designer, and press the Install button at the bottom of the window. The following screen will appear:
  9. iReport 3.7

  10. Press Next >, and accept the terms of the License Agreement.
  11. iReport 3.7

  12. If the Verify Certificate dialog box appears, click Continue.
  13. iReport 3.7

  14. Press Install, and wait for the installer to complete the installation.
  15. iReport 3.7

  16. After the installation is done, press Finish and close the Plugins dialog. If the IDE requests for a restart, then do it. Now the IDE is ready for creating reports.

iReport 3.7

Creating reports

We have already learnt about creating various types of reports, such as reports without parameters, reports with parameters, reports with variables, subreports, crosstab reports, reports with charts and images, and so on. We have also attained knowledge associated with these types of reports. Now, we will learn quickly how to create these reports using NetBeans with the help of the installed iReport plugins.

Creating a NetBeans database JDBC connection

The first step is to create a database connection, which will be used by the report data sources. Follow the listed steps:

  1. Select the Services tab from the left side of the project window.
  2. Select Databases.
  3. Right-click on Databases, and press New Connection….
  4. iReport 3.7

  5. In the New Database Connection dialog, set the following under Basic setting, and check the Remember password checkbox:

Option

Value

Driver Name

MySQL (Connector/J Driver)

Host

localhost

Port

3306

Database

inventory

User Name

root

Password

packt

iReport 3.7

  1. Press OK. Now the connection is created, and you can see this under the Services | Databases section, as shown in the following screenshot:

iReport 3.7

Creating a report data source

The NetBeans database JDBC connection created previously will be used by a report data source that will be used by the report. Follow the listed steps to create the data source:

  1. From the NetBeans toolbar, press the Report Datasources button. You will see the following dialog box:
  2. iReport 3.7

  3. Press New.
  4. Select NetBeans Database JDBC connection, and press Next >.
  5. iReport 3.7

  6. Enter inventory in the Name field, and from the Connection drop-down list, select jdbc:mysql://localhost:3306/inventory [root on Default schema].
  7. iReport 3.7

  8. Press Test, and if the connection is successful, press Save and close the Connections / Datasources dialog box.

iReport 3.7

Creating a simple report

We are going to create a report, which shows the list of products. Just follow the listed steps:

  1. Go to File | New File….
  2. Select Report from the Categories: section and Report Wizard from the File Types: section, as shown in the next screenshot:
  3. iReport 3.7

  4. Press Next >. Select the Simple Blue layout and press Next > again.
  5. iReport 3.7

  6. Enter ProductListNB.jrxml as File Name:, and Browse… to the reports folder.
  7. iReport 3.7

  8. Press Next >.
  9. iReport 3.7

  10. Select inventory from the Connections / Data Sources options.
  11. Write the following SQL command as the query:
      SELECT ProductCode, Name, Description
      FROM Product
  12. Press Next >. You will see the following screen:
  13. iReport 3.7

  14. Select all the fields, press >>, and then press Next >.
  15. Press Next > again without selecting any group.
  16. iReport 3.7

  17. Press Finish. You will see the following output:
  18. iReport 3.7

  19. Click on the Preview button to see the output, as shown in the following screenshot:
  20. iReport 3.7

  21. You can design the report in the Designer section as per your design requirements.

Creating a parameterized report

We are going to create a report in NetBeans that shows the personal information of a particular customer. Follow the listed steps:

  1. Go to File | New File….
  2. Go to File | New File….
  3. Select Report from the Categories: section and Report Wizard from the File Types: section.
  4. Press Next > and select Simple Blue and press Next > again.
  5. Enter ParticularCustomerNB.jrxml as the File Name:.
  6. Browse… to the reports folder.
  7. Press Next >.
  8. Select inventory from the Connections / Data Sources drop-down list.
  9. Write the following SQL command as the query:

    SELECT * FROM Customer

    iReport 3.7

  10. Press Next >.

    iReport 3.7

  11. Select all the fields, press >>, and then press Next >.>>
  12. Press Next > again without selecting any group.
  13. Press Finish. You will see the Designer view of the report.
  14. From the Report Inspector (see bottom left of the designer), select Parameters. Right-click on it, and click on Add Parameter.
  15. iReport 3.7

  16. A parameter named parameter1 is added to the Parameters list. Select parameter1, and go to the parameter Properties window (see bottom-right of the designer).
  17. iReport 3.7

  18. Change the Name to customerNo.
  19. Change the Parameter Class to java.lang.Integer.
  20. Check the Use as a prompt checkbox.
  21. Now, click on Report query (beside the Preview button), and replace the query with the following one:
      SELECT * FROM Customer
      WHERE CustomerNo = $P{customerNo}
  22. iReport 3.7

  23. Press OK and Preview the report. Input the customerNo, and see the output.

Summary

We have seen that creating iReport reports in NetBeans makes the process of developing and managing reports easier. We have got an initial idea of creating reports in NetBeans. In the same way, we can create the more complex reports (subreports, crosstab reports, reports with charts, and so on) as well.


If you have read this article you may be interested to view :

Books to Consider

comments powered by Disqus