Setting the database user name and password at run time
When a report accesses data in a database, a typical action is to prompt the report user to type his user name and password at run time. You accomplish this action by using report parameters. Report parameters provide a mechanism for getting values at run time and passing the values to the report.
The following procedure shows how to create report parameters and bind the parameters to the user name and password properties in a JDBC data source.
How to enable a user to provide a database user name and password when a report runs
This procedure assumes that you have already created a JDBC data source.
1 Create a report parameter to get the user name, using the following steps:
1 In Data Explorer, right-click Report Parameters, then choose New Parameter.
2 In New Parameter, supply the following information:
*In Name, type a name for the report parameter. For example:
username_param
*In Prompt text, specify a word or sentence to prompt the report user to provide a user name value. For example:
User name
*In Data type, select String.
Figure 1‑10 shows the completed report parameter definition.
Figure 1‑10 Report parameter to get the user name
3 Choose OK. The username_param parameter appears under Report Parameters in Data Explorer.
2 Use the previous steps to create a report parameter to get the password. Use the following values to define the report parameter:
*In Name, type:
password_param
*In Prompt text, type:
Password
*In Data type, select String.
3 Choose OK. The password_param parameter appears under Report Parameters in Data Explorer.
4 Bind the user name property to the username_param report parameter.
1 In Data Explorer, right-click the JDBC data source, then choose Edit.
2 In Edit Data Source, choose Property Binding. The Property Binding page displays the JDBC connection properties.
3 Choose the expression builder button on the right of User Name.
4 In the expression builder, perform the following tasks:
*Under Category, choose Report parameters. All appears under Sub‑Category.
*Choose All. Under Double Click to insert, BIRT Designer displays the report parameters that you created.
*Double-click the username_param report parameter. The expression params["username_param"].value appears in the text area, as shown in Figure 1‑11.
Figure 1‑11 Choosing the username_param in the expression builder
*Choose OK. The expression builder closes. The report parameter expression appears in the User Name field, as shown in Figure 1‑12.
Figure 1‑12 User Name property bound to the username_param report parameter
5 Using the previous steps, bind the password property to the password_param report parameter.
5 In Edit Data Source, choose OK.
6 Preview the report to confirm that the user is prompted for a user name and password. Figure 1‑13 shows Enter Parameters, the dialog that prompts the user to enter a user name and password.
Figure 1‑13 Enter Parameters prompts the user for a user name and password
The values that the user specifies are used to connect to the JDBC database.