The query in the report unit determines the data that the server retrieves from a data source. You can use an existing query or define a new one. You can create multiple reports that look the same but contain different data by defining different queries for the same JRXML file. The simple report example defines a custom query that displays accounts from a single country.
To define a custom query for the simple report example:
| 1. | In the JasperReport wizard, click Query. |
The Locate Query page presents these choices:
| • | Do not link a Query – Uses the query, if there is one, defined within the main JRXML. If the main JRXML doesn’t have a query, you can’t run the report. |
| • | Click here to create a new Query – Guides you through defining a new query, only available to your report. |
| • | Select a Query from the Repository – Selects an existing query from the repository. |
The AllAccounts.jrxml file uploaded in Uploading the Main JRXML already contains a query. This example overrides the existing query by defining a new one.
| 2. | On the Query page, select the Click here to create a new Query option: |
|
Query Page |
| 3. | Click the link, Click here to create a new Query. |
The Name the Query page appears where you can enter the name, resource ID, and description of the query. This query and its properties are visible only within the report unit.
| 4. | In this example, the query must retrieve only Canadian accounts. Enter the following values: |
| • | Resource ID – CanadaAccounts |
| • | Description – Query for New Simple Report in User Guide |
|
Name the Query Page |
The Link a Data Source to the Query page appears.
The Link a Data Source to the Query page appears. You can select a query from the repository, define a new one, or select not to link a data source.
| 7. | Click Next. The Define the Query page appears. |
| 8. | Select SQL in the Query Language drop-down and enter the following Query String to retrieve only Canadian accounts: |
SELECT * FROM accounts WHERE billing_address_country = ‘Canada’ ORDER BY billing_address_city
|
Definition of a Query |
| 9. | Click Save to save the query. The Customization page appears. No customization is required. |
| 10. | Click Submit to submit the new report unit to the repository. |
Recommended Comments
There are no comments to display.