change Birt report datasource from java

1.7k views Asked by At

We have created Birt reports in eclips Report design and we use Birt jdbc Data source to connect to a derby database. Now we will use the same reports with mysql database. Each time we need to edit this datasource in each report. We would like to have a property in java/maven where we could change the Driver Class and Database URL.

We already followed the instructions on this link How to set a datasource for a BIRT report programmatically?

But here he will use dynamic database url at runtime. But don't want this at runtime, it has to change permanent until we change it again trough maven.

1

There are 1 answers

1
Ibrahim B. On

We found a solution to do this. In birt report we use jdbc data source (property binding):

if ( params["database"] == "derby" ){
     "jdbc:derby://localhost:1527/databaseName;user=user;password=password";
}else if ( params["database"] == "mysql" ) {
     "jdbc:mysql://localhost:3306/databaseName?user=root";
}

so we created a parameter where we can select derby or mysql at runtime.

We use also report web viewer, so we show this report in a webpage :

<birt:viewer id="WebApp" reportDesign="report.rptdesign" format="html" ></birt:viewer>

Now we pas the parameter in this viewer like this:

<birt:viewer id="WebApp" reportDesign="report.rptdesign" format="html" >
      <birt:param name="database" value='mysql'></birt:param>
</birt:viewer>

the parameter value will automatically change by using maven profiles.