Jump to: navigation, search

Difference between revisions of "Change Database URL at runtime based on Parameter (BIRT)"

(New page: {{Backlink|Report Developer Examples (BIRT)}} This example is [https://bugs.eclipse.org/bugs/show_bug.cgi?id=187941 Bugzilla ID 187941]. If you would like to contribute an example see the...)
 
(Description)
 
Line 11: Line 11:
 
== Description==  
 
== 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.
 
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 bring up 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.
+
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 ){
 
  if ( params["Production"] == true ){
Line 22: Line 22:
  
 
Next add the Production boolean parameter and create your data set.  Create a table that uses the data set and test the report.
 
Next add the Production boolean parameter and create your data set.  Create a table that uses the data set and test the report.
 +
 
== Comments ==  
 
== Comments ==  
 
Please enter comments below by selecting the edit icon to the right.
 
Please enter comments below by selecting the edit icon to the right.

Latest revision as of 21:45, 18 May 2007

< 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.