Before you can use dynamic queries, you are required to first make some preparations.
The dynamic query interface is set as a property in the JDBC connection object in a catalog.
In JReport Designer, launch the Catalog Browser, expand the data source node, select the JDBC connection, right-click it and select Properties from the shortcut menu to display the properties of the connection. You will then see the SQL Statement Creator property, which is used to set the real class name of the dynamic query object.
Here are a couple of examples:
Notes:
. In the Options dialog, select Catalog in the Category box and uncheck forbid editing data object properties. Then, go back to the Catalog Browser, and highlight the column name that you want to edit to change or set the property values for.In the Catalog Browser, in the Properties sheet of a highlighted query, there is a property named Enable SQL Statement Creator, which indicates whether or not the query uses the dynamic query interface to get the result set. When it is set to true, the query can be re-generated at runtime using the dynamic query interface.
You are provided with a demo program, SQLStmtCreatorImpl.java in <install_root>\help\samples\APIDynamicQuery, which implements the dynamic query interface. This demo is for changing the table name of the query sent to the database. Specifically, when you run the report, if you enter 1 as the tableIndex parameter, the query will dynamically change to Customers1. If you do not enter anything, you will get the result set from the Customers table.
The following example explains how to compile the required files and use dynamic queries in a report:
Assume that JReport Designer has been installed in C:\JReport\Designer, and the class files of the MappingNameFinder.java are in C:\JReport\Designer\help\samples\APIDynamicQuery:
javac -classpath c:\jreport\designer\lib\JREngine.jar;c:\jreport\designer\help\samples\APIDynamicQuery SQLStmtCreatorImpl.java
Note: To compile SQLStmtCreatorImpl.java you will need another file MappingNameFinder.java in <install_root>\help\samples\APIDynamicQuery.
<install_root>\bin by appending the SQLStmtCreatorImpl.java path into the batch file's ADDCLASSPATH variable:
set ADDCLASSPATH=%JAVAHOME%\lib\tools.jar;C:\jreport\designer\help\samples\APIDynamicQuery;
<install_root>\Demo\Reports\SampleComponents, then open the sample report BandedObjectReport.cls.
on the toolbar, then set the value of the SQL Statement Creator property as SQLStmtCreatorImpl;@tableIndex. The parameter tableIndex is used to specify which table is to be selected at runtime.