iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library iReport Ultimate Guide - Nimsoft Library

13.07.2015 Views

iReport Ultimate GuideFigure 2-11Oracle Driver Loaded from an External JARResume the testing without closing iReport by copying the JDBC driver into the /lib directory and clicking Test again. iReportautomatically locates the required JAR file and loads the driver from it. In Chapter 11, I will explain the configurationmethods for various data sources in greater detail.If the test is successful, click the Save button to store the new connection.The connection will appear in the data source drop-down list in the main tool bar (Figure 2-12). Select it to make it the activeconnection.Another way to set the active connection is by opening the data source window (Figure 2-12):1. Select the Tools → Report data sources menu item (or by clicking the button on the tool bar next to the data sources dropdownlist).2. Select the data source that you want to make active:Figure 2-12Data Sources Window3. Click Set as default.The selected data source is the one used to fill the report and perform other operations, such as the acquisition of the fieldsselected through SQL queries. There is no strict binding between a report and a data source, so you can run a report withdifferent data sources, but only one at time. Later, we will see how subreports can be used to create a report that uses multipledata sources.24

Getting StartedThe Data Sources drop-down menu allows you to select the active data source; the ◄ button on the left opens the Data Sourceswindow:Figure 2-13Data Sources Drop-Down Menu2.10 Creating Your First ReportNow that you have installed and configured iReport and prepared a JDBC connection to the database, you will proceed tocreate a simple report using the Wizard.For this example and many of those following, you will use HSQLDB, a small relational database written in Java and suppliedwith a JDBC driver. You can learn more about this small jewel by visiting the HSQLDB web site.2.10.1 Using the Sample DatabaseFor sample reports, we will use the sample database that comes with JasperReports.Download JasperReports (the biggest distribution) and unpack it. Open a command prompt (or a shell) and change to the/demo/hsqldb. IIf you have Ant (and you know what it is), just run:ant runServerOtherwise, run this command (all in a single line):java -cp ..\..\lib\hsqldb-1.7.1.jar org.hsqldb.ServerThe database server will start and we will be ready to use it with iReport.2.10.2 Using the Report WizardThe table below lists the parameters you should use to connect to the sample database:ParameterNameJDBC DriverJDBC URLUsernameValueJasperReports Sampleorg.hsqldb.jdbcDriverjdbc:hsqldb:hsql://localhostsaPasswordWhen the password is blank, as in this case, remember to set the Save password check box when configuring the connection.1. Click File → Report Wizard. This loads a wizard (Figure 2-14) for the step-by-step creation of a report, starting with theselection of the template followed by the selection of the name and the location of the new report.25

<strong>iReport</strong> <strong>Ultimate</strong> <strong>Guide</strong>Figure 2-11Oracle Driver Loaded from an External JARResume the testing without closing <strong>iReport</strong> by copying the JDBC driver into the /lib directory and clicking Test again. <strong>iReport</strong>automatically locates the required JAR file and loads the driver from it. In Chapter 11, I will explain the configurationmethods for various data sources in greater detail.If the test is successful, click the Save button to store the new connection.The connection will appear in the data source drop-down list in the main tool bar (Figure 2-12). Select it to make it the activeconnection.Another way to set the active connection is by opening the data source window (Figure 2-12):1. Select the Tools → Report data sources menu item (or by clicking the button on the tool bar next to the data sources dropdownlist).2. Select the data source that you want to make active:Figure 2-12Data Sources Window3. Click Set as default.The selected data source is the one used to fill the report and perform other operations, such as the acquisition of the fieldsselected through SQL queries. There is no strict binding between a report and a data source, so you can run a report withdifferent data sources, but only one at time. Later, we will see how subreports can be used to create a report that uses multipledata sources.24

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!