Home
Analytics
Passing DB connection to BIRT
RohanKK
Hi,
I want to pass DB connection object to BIRT and want to use the same in the rpt design file . Please let me know what are the changes I have to do ?
Regards,
Rohan
Find more posts tagged with
Comments
johnw
Not sure what you mean by a "DB Connection Object". If your refering to a JDBC URL string, you just pass it as a parameter, and use the Property Binding tab in your data source.
If your refering to a JDBC Connection object, and you want to reuse it, it will require some refactoring of the JDBC ODA, or the use of a scripted data source.
Take a look at the following article, it uses a ResultSet, but the idea would be the same.
http://techieocean.blogspot.com/2009/06/how-to-pass-resultset-to-birt-report.html
John
RohanKK
Thanks John,
I meant JDBC connection object. Actually I don't want to use scripted data source as it will required changes to multiple existing report.
Can't we make BIRT to use, custom connection object provided at runtime ?
JasonW
Take a look at this post:
http://birtworld.blogspot.com/2008/11/birt-connection-pooling-continued-again.html
Jason
PKofon
<blockquote class='ipsBlockquote' data-author="'RohanKK'" data-cid="69457" data-time="1287403135" data-date="18 October 2010 - 04:58 AM"><p>
Thanks John, <br />
I meant JDBC connection object. Actually I don't want to use scripted data source as it will required changes to multiple existing report. <br />
<br />
Can't we make BIRT to use, custom connection object provided at runtime ?<br /></p></blockquote>
<br />
If I understand you correctly, you want to pass a custom JDBC connection object to BIRT. This is exactly what I do:<br />
<br />
runTask.getAppContext().put("OdaJDBCDriverPassInConnection", myConnectionProvider.getConnection())<br />
<br />
where runTask is an instance of IRunTask and myConnectionProvider is an instance of a custom class that knows how to obtain a JDBC connection, which in my case, is from a connection pool. What's cool about this is that in production, your reports can point to a data source controlled by your application so that connection properties (which may change) can be managed in one place so you avoid making changes to multiple reports. Note that the method on your connection provider doesn't have to be called getConnection(), it's just self-describing.
RohanKK
Hi PKofon,
After adding JDBC connection in app context , what are the other steps you are doing to use this connection in the Rpt design file ?
-Rohan
PKofon
<blockquote class='ipsBlockquote' data-author="'RohanKK'" data-cid="69480" data-time="1287425628" data-date="18 October 2010 - 11:13 AM"><p>
Hi PKofon, <br />
After adding JDBC connection in app context , what are the other steps you are doing to use this connection in the Rpt design file ?<br />
<br />
<br />
<br />
-Rohan<br /></p></blockquote>
<br />
<br />
Rohan,<br />
<br />
No other steps are required. This ignores the connection you have defined in the report design file. <br />
<br />
I use it to make sure my reports run against the data source that the application is using in production. Your requirements may be different from mine. I've embedded BIRT in my application and the reports have to run against either a PostgreSQL, Oracle or Microsoft SQL database. I don't want to keep changing DB connection parameters in each of the reports - what I used to do actually. I just do so once in the connection properties file of the application.
RohanKK
Hi PKofon,
With following changes I am able to provide my JDBC connection Object to BIRT.
"runTask.getAppContext().put("OdaJDBCDriverPassInConnection", myConnectionProvider.getConnection())"
But after every report run BIRT is closing the connection, I want to override the closing of connection behavior and want to provide my custom handler. Can we do this ?
Thanks a lot for your help.
-Rohan
PKofon
<blockquote class='ipsBlockquote' data-author="'RohanKK'" data-cid="69499" data-time="1287470426" data-date="18 October 2010 - 11:40 PM"><p>
Hi PKofon, <br />
With following changes I am able to provide my JDBC connection Object to BIRT.<br />
<br />
"runTask.getAppContext().put("OdaJDBCDriverPassInConnection", myConnectionProvider.getConnection())"<br />
<br />
<br />
But after every report run BIRT is closing the connection, I want to override the closing of connection behavior and want to provide my custom handler. Can we do this ?<br />
<br />
<br />
Thanks a lot for your help. <br />
<br />
-Rohan<br /></p></blockquote>
<br />
Yes, you can. BIRT calls connection.close() on your connection object when it's done with your report and, that of course, closes the connection. However, if your connection is from a pool (and I recommend you use one, e.g. Apache DB Connection Pool), BIRT will still call close() but instead of the connection being closed permanently, it's returned to the pool by the pool manager so it can be reused. Look up <a class='bbc_url' href='
http://commons.apache.org/dbcp/.'>http://commons.apache.org/dbcp/.</a>
; You can put the logic of obtaining a connection from the pool in a method such as the getConnection() method I talked about earlier.<br />
<br />
Regards,<br />
<br />
Paul
smarcin
<blockquote class='ipsBlockquote' data-author="'PKofon'" data-cid="69508" data-time="1287490464" data-date="19 October 2010 - 05:14 AM"><p>
Yes, you can. BIRT calls connection.close() on your connection object when it's done with your report and, that of course, closes the connection. However, if your connection is from a pool (and I recommend you use one, e.g. Apache DB Connection Pool), BIRT will still call close() but instead of the connection being closed permanently, it's returned to the pool by the pool manager so it can be reused. Look up <a class='bbc_url' href='
http://commons.apache.org/dbcp/.'>http://commons.apache.org/dbcp/.</a>
; You can put the logic of obtaining a connection from the pool in a method such as the getConnection() method I talked about earlier.<br />
<br />
Regards,<br />
<br />
Paul<br /></p></blockquote>
<br />
Hi, I'm new to BIRT and have similar task to do, I mean I need to override standard way of connection to DB. But I don't know:<br />
1) where to put this code you've submitted<br />
2) where to provide getConnection() method.<br />
<br />
Could you help me?
PKofon
<blockquote class='ipsBlockquote' data-author="'smarcin'" data-cid="69632" data-time="1287735800" data-date="22 October 2010 - 01:23 AM"><p>
Hi, I'm new to BIRT and have similar task to do, I mean I need to override standard way of connection to DB. But I don't know:<br />
1) where to put this code you've submitted<br />
2) where to provide getConnection() method.<br />
<br />
Could you help me?<br /></p></blockquote>
<br />
@smarcin
,<br />
<br />
Please take a look at <a class='bbc_url' href='
http://wiki.eclipse.org/Servlet_Example_(BIRT)_2.1.'>http://wiki.eclipse.org/Servlet_Example_(BIRT)_2.1.</a>
; It's an example that describes how to use BIRT within a Servlet. Once you have an IRunTask or an IRunAndRenderTask object, you can call getAppContext() and provide a custom connection just like in the code snippet I provided. The first thing you need to do though, is to follow the example and make sure you can run reports. After that you can start worrying about providing BIRT a custom connection. Good luck.
smarcin
<blockquote class='ipsBlockquote' data-author="'PKofon'" data-cid="69680" data-time="1287944549" data-date="24 October 2010 - 11:22 AM"><p>
@smarcin
,<br />
<br />
Please take a look at <a class='bbc_url' href='
http://wiki.eclipse.org/Servlet_Example_(BIRT)_2.1.'>http://wiki.eclipse.org/Servlet_Example_(BIRT)_2.1.</a>
; It's an example that describes how to use BIRT within a Servlet. Once you have an IRunTask or an IRunAndRenderTask object, you can call getAppContext() and provide a custom connection just like in the code snippet I provided. The first thing you need to do though, is to follow the example and make sure you can run reports. After that you can start worrying about providing BIRT a custom connection. Good luck.<br /></p></blockquote>
Many thanks PKofon. BTW: there's dot '.' at the end of link you've provided. Just to everybody be aware of it.
smarcin
Hi
Firstly I have to say that this example is still not clear for me. I stuck in the moment of creation webreport.jar. Basically I'm using Birt v.2.6.1 while the most up to date code in this example is for v.2.5.0. Secondly Tomcat Eclipse plug-in: servlet.jar is for version 4.x I guess and I'm using 5.x as far as I remember.
No matter that I compiled three files BirtConfig.properties, BirtEngine.java and WebReport.java into webreport.jar. I hope everything I did was done properly.
But now there are some point which are totally unclear for me. But how below comment could be clear for newbies:
"Note that if your report references classes from your application, the following code is required in order for the RunAndRenderTask/RunTask to use your application's classloader:
config.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, Thread.currentThread().getContextClassLoader());
You can also add to your classpath using the following appcontext setting; This can be used to setup jars that implement event handlers.
config.getAppContext().put(EngineConstants.WEBAPP_CLASSPATH_KEY, "c:/jars/mjo.jar");
Modify the appcontext before starting up the Platform.
Platform.startup( config );
This behaviour has changed from earlier versions of BIRT. See example version for 2.2 at the bottom of page."
Please help in next steps.
radhe_7887
<blockquote class="ipsBlockquote" data-author="PKofon" data-cid="69474" data-time="1287419783">
<div>
<p>If I understand you correctly, you want to pass a custom JDBC connection object to BIRT. This is exactly what I do:<br><br>
runTask.getAppContext().put("OdaJDBCDriverPassInConnection", myConnectionProvider.getConnection())<br><br>
where runTask is an instance of IRunTask and myConnectionProvider is an instance of a custom class that knows how to obtain a JDBC connection, which in my case, is from a connection pool. What's cool about this is that in production, your reports can point to a data source controlled by your application so that connection properties (which may change) can be managed in one place so you avoid making changes to multiple reports. Note that the method on your connection provider doesn't have to be called getConnection(), it's just self-describing.</p>
</div>
</blockquote>
<p> </p>
<p>Hi PKofon,</p>
<p>Your example shows how to pass JDBC connection from java to BIRT rptdesign. I'm already using this with RunAndRender task. But, recently we have moved to Flat file data source. Is there any setting to pass in flat file data source connection in the same way as above?</p>
<p> </p>
<p>Thanks,</p>
<p>Radhe</p>