#### Example 4: Developing reports with dynamic UDS

JReport Designer supports the Dynamic UDS feature. This feature improves performance significantly by retrieving the selected 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).

1. Open an existing catalog.
2. In the Data tab of the Catalog Browser, expand the data source to which the UDS is to be added.
3. Right-click the Parameters node and select Add Parameter from the shortcut menu.
4. In the Create Parameter dialog, enter the following:
   - Parameter Name: sql
   - Value Type: String
   - Prompting Values:

     select * from employee
     select salary from employee
     select employeeid, employeeposition, hiredate, notes, salary, photo from employee

     For details about how to create a parameter, see Creating a parameter.

5. Right-click the User Defined node, and then select Add User Defined Data Source from the shortcut menu.
6. In the Add User Data Source dialog, enter the following information:
   - Name: employees
   - Class Name: help.SQLDataSource
   - Parameters: `DRIVER="org.hsqldb.jdbcDriver"&URL="jdbc:hsqldb:C:\\JReport\\Designer\\Demo\\db\\DemoDB"&USER=sa&PSWD=&SQL=@sql`

   The UDS employees will now have been added to the catalog.

7. Click on the Standard toolbar to open an existing report set, and then select File > New > Report.
8. In the New Report dialog, specify the name and layout of the report as required and then click Create. Here, we choose to create a table report.
9. In the Data tab of the Table Report Wizard, check the New radio button and choose the UDS employees from the User Defined node. Then, click Next to go to the next tab.
10. In the Display tab, 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.
11. In the Group tab, specify to group on the field EMPLOYEEPOSITION.
12. Skip the Summary tab and in the Layout and Style tab, specify to display the report in the Warm style.
13. Click Finish to create the report.
14. Click the View tab to view the report. You will then be prompted to enter a parameter.
15. Select select * from employee as the parameter, and you will see that data for all fields has been retrieved. See the result.

16. Go back and run this report again. This time, choose select salary from employee. You will notice that no groups are divided 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. See the result.

Note: To make a dynamic UDS work fine, 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 is edited, that is the Specify columns option in the Add User Data Source dialog should be unchecked, otherwise exceptions will be produced when the SQL statement is used to generate dynamic report from the UDS.