For users who wish to write their own SQL statement, JReport enables them to put the SQL statement into a file and then load them from this file. Note that at present each SQL file can only contain one SQL statement.
Usually, you can save the file containing the SQL statement as a plain text file (.txt). The SQL statement here supports the SQL 92 standard. Although for different databases, it may vary. The basic statement is:
SELECT...FROM...WHERE
Nested query is also supported.
The following is an example of an SQL file:
|
The SQL files can work like queries in JReport, but there are two basic differences:
In addition, JReport Designer provides you with the Data Manager which allows you to control the data retrieval of your SQL files that function as queries, including the number of rows to be displayed and the duration required for the retrieval. It can also keep access information from previous runs of an SQL file.
After you have set up the JDBC connection and created some SQL files, you can then add them to a catalog. To do this:
Notes:
WHERE (Products."Product Type ID"=Catalog."Product Type ID") AND ("Orders Detail"."Product ID"=Products."Product ID") AND (Orders."Customer ID"=Customers."Customer ID") AND (Orders."Order ID"="Orders Detail"."Order ID") AND ( ( Customers.Country='USA' )) AND (Customers."Customer ID" > @id)
Where, id is a parameter created in the catalog.
WHERE (@COL_DATE = to_date(@p_DATE,'yyyy-mm-dd')
WHERE (@COL_DATE = to_date('2003-12-06','yyyy-mm-dd')
If you make any changes to SQL files in the database, you will need to update them in the connection so that reports built on them can work properly. To do this:
When you have added some SQL files to a catalog, you can then use them to develop reports as required.
By default, when you run a report, JReport Engine fetches data from the database using the JDBC driver. For reports that are built on imported SQL files which function as queries, JReport enables you to create cached result files and save them somewhere in your machine. Then, when you view these reports, you can choose to use the data from the cached query result file as opposed to the database.
For details about cached query results, see Cached query results.