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 uses a custom query that returns 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 – Select this option to use a query already defined within the main JRXML. |
| • | Click here to create a new Query – Guides you through defining a new query for this report only. |
| • | Select a Query from the Repository – Select a 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. | 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. |
| 4. | Enter the name, resource ID, and description of the query.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 |
This query and its properties are visible only within the report unit.
|
Name the Query Page |
| 5. | Click Next. 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 for the example. |
| 10. | Click Submit to submit the new report unit to the repository. |
Recommended Comments
There are no comments to display.