Example 1: Importing from a database

In the sample program ParamTest.java in <install_root>\help\samples\APIParameter, different values were assigned to the parameter p_StartDate by accessing values from an HSQL database. In addition, the sample report CustomerAnalysis.cls uses this parameter in the query condition. So here, we use this demo report as an example to explain how to import parameter values from a database, so that you do not need to type in the values one by one while specifying the parameter default value (note that in this example we assume your JReport Designer is installed in the default path, that is C:\JReport\Designer).

  1. Compile ParamTest.java to generate ParamTest.class, and store the class file in C:\JReport\Designer\help.

    javac -classpath c:\JReport\Designer\lib\JREngine.jar; ParamTest.java
  2. Append C:\JReport\Designer\help to the ADDCLASSPATH variable of setenv.bat in C:\JReport\Designer\bin.
  3. Start JReport Designer and open CustomerAnalysis.cls.
  4. In the Report Inspector, find the report property Import Parameter Values, and input the class name with the full package name. In this example, input help.ParamTest, and then set the property Parameter List Auto to false.

    Tip: The report node is not shown in the resource tree of the Report Inspector by default. To have it shown, select the report tab node in the tree (in this example, the CustomerAnalysis node), and then click the Up button on the Report Inspector toolbar.

  5. Save the report and catalog, and then view the report result.
  6. In the Enter Parameter Values dialog, click the drop-down list of the parameter. You will find that all the values you specified in ParamTest.java have been imported into the list.
  7. Select one of the values with which to view the report.
  8. Publish the saved report CustomerAnalysis.cls to JReport Server (for details, see Publishing resources remotely).
  9. Append C:\JReport\Designer\help to the ADDCLASSPATH variable of setenv.bat in <server_install_root>\bin.
  10. Start JReport Server with the modified batch file.
  11. Load your web browser to access the JReport Server Console Page. You will then have the same parameter values as you did in JReport Designer.

Note: In the sample ParamTest.java, we used the method compareToIgnoreCase( ) to compare the parameter name in the class file with the one in your report. This method is not case sensitive when performing the comparison.