Previous Page Next Page
Example 4: Adding a Dynamic UDS
JReport Designer supports the Dynamic UDS feature. This feature improves performance by retrieving only the selected fields and not all the fields. At runtime, an option is provided for you to pick up the columns you want to see in the report. In this way, JReport Designer generates a dynamic report according to your selection.
In this example, SQLDataSource is used to illustrate the usage and effect of the Dynamic UDS feature. Assume that you have generated SQLDataSource.class, start JReport Designer with the modified batch file (for details, see Compiling and running SQLDataSource).
- Open an existing catalog.
- In the Catalog Manager resource tree, expand the data source to which the UDS is to be added.
- Create a parameter with the following information:
- Name: sql
- Value Type: String
- Prompt Values:
select * from employee
select salary from employee
select employeeid, employeeposition, hiredate, notes, salary, photo from employee
- Right-click the data source node, and then select New User Defined Data Source from the shortcut menu.
- In the New User Defined Data Source dialog, enter the following information:
- Name: employees
- Class Name: SQLDataSource
- Parameter:
DRIVER="org.hsqldb.jdbcDriver"&URL="jdbc:hsqldb:C:\\JReport\\Designer\\Demo\\db\\JRDemo"&USER=sa&PSWD=&SQL=@sql
- Click OK to add the UDS.
Next, we will create a page report directly on the UDS to test the Dynamic UDS feature. If you want to create web reports and library components on this UDS, you need to first create a business view using this UDS.
- Click Home/File > New > Page Report.
- In the Select Component for Page Report dialog, specify the report title and choose the Table (Group Left) component. Click OK.
- In the Data screen of the Table Wizard, choose the UDS employees from the User Defined node. Then, click Next.
- In the Display screen, add the fields EMPLOYEEID, employees_NOTES, employees_SALARY and HIREDATE to be displayed in the table, edit their display names to ID, Notes, Salary, Hire Date, and then click Next.
- In the Group screen, specify to group on the field EMPLOYEEPOSITION.
- Skip the Summary, Chart and filter screens, and in the Style screen, specify to display the report in the Warm style.
- Click Finish to create the report.
- Click the View tab to view the report. You will then be prompted to enter a parameter.
- Select select * from employee as the parameter, and you will see that data for all fields has been retrieved.

- Go back and run this report again. This time, choose select salary from employee. You will notice that no groups are displayed and the group name changes to NULL. This is because only the field employees_SALARY has been selected this time. JReport Designer will make no reference to the employees_Position column, on which the group is based.

Note: To make a dynamic UDS work, if the SQL statement at runtime doesn't include all the UDS columns, you need to make sure that none of the UDS columns' properties were edited, that is the Specify Columns option in the New User Defined Data Source dialog should be unchecked, otherwise exceptions will be produced when the SQL statement is used to generate a dynamic report from the UDS.
Previous Page Next Page