Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Change Database URL at runtime based on Parameter (BIRT)

< To: Report Developer Examples (BIRT)
This example is Bugzilla ID 187941. If you would like to contribute an example see the example contribution guidelines.

Introduction

BIRT Provides the ability to change Data Source and Data Set properties at runtime. These include properties like username, password, database url, and the query. This example illustrates changing the database url. This would typically be done when you are developing against a development database and want to swap the database to production.

BIRT Version Compatibility

This example was built and tested with BIRT 2.1.2.

Example Files

Add a URL to your bugzilla attachment. eg. Example Report

Description

Changing the database url can be done with scripting in the event handlers or using property binding. In this example we will do it with property binding. After your data source is added double click on it to launch the data source editor and select the Property Binding entry. Select the expression builder button next to the JDBC Driver URL and enter the following expression.

if ( params["Production"] == true ){
     "jdbc:mysql://localhost/classicmodels";
}else{
     "jdbc:mysql://localhost/qa";
}

Note that this example expects that you are using MySQL and the classic models sample database. This expression checks for a boolean parameter named Production and if its value is true use the classicmodels sample database. If the value is false it will use the qa database. If your system has no qa database you will get no results.

Next add the Production boolean parameter and create your data set. Create a table that uses the data set and test the report.

Comments

Please enter comments below by selecting the edit icon to the right. You will need a Bugzilla account to add comments.


Back to the top