Home
Analytics
Using JDBC connection in Java event handler
DButtery
Hi all,
Where do I need to place my JDBC driver jar such that it can be accessed from within a Java event handler (specifically the 'beforeFactory' handler) ??
I currently have the jar file placed in the:
... birt-viewerWEB-INFplatformpluginsorg.eclipse.birt.report.data.oda.jdbc_2.3.1.v20080827drivers
folder and my report's data sources are quite happy with that. The event handler, however, throws a ClassNotFoundException when I try to load the driver class.
Questions:
1) How can I get the event handler code to see the driver jar file?
2) Can I place the jar file somewhere else such that both the event handler and the report's data sources can access it?
3) Is is possible to create a report data source that can be used directly in the beforeFactory event handler to pull in required data prior to the report actually being generated?
The premise here is that my application front-end is storing the report parameters for a given user in the database. When the user requests the report to be generated the app will only send the key info to the birt-viewer. The 'beforeFactory' event handler for the report then needs to connect to the database and retreive and set the report parameters for that run.
Thanks in advance for any help you can provide!
-Dennis
Find more posts tagged with
Comments
JasonW
Dennis,
Can you try putting the driver in the WEB-INF/lib folder of the viewer? In the beforeFactory before calling your code to connect add
reportContext.getAppContent().put("OdaJDBCDriverClassPath",
"fullpathtoViewer/WEB-INF/lib");
Jason
DButtery
Jason,
That works great! Thanks!
Obvious next question though ...
Is there an example of accessing a properties file (or such) from the event handler? Is there a way to access the BIRT home setting? Right now, my prototype has a lot of hard-coded paths/values that can't be there for a true deployable app ...
Thanks again,
-Dennis
JasonW
Dennis,
If the resource has been attached to the report using the general properties for the report you should be able to get values using the
reportContext.getResource(..); method.
DButtery
Jason,
That would probably work...
I'm looking, however, for a solution that decouples those resources from the reports themselves.
My event handler is intended to be common and will be referenced by all of my report designs.
Is there a way to access resources/properties from the viewer itself, regardless of the report that is being generated?
-Dennis
JasonW
Dennis,
Does this type of code work?
ClassLoader cl = Thread.currentThread ().getContextClassLoader();
InputStream in = null;
in = cl.getResourceAsStream ("propertyfileinclasspath");
Properties configProps;
configProps.load(in);
in.close();
Jason
DButtery
Jason,
Success!! That works like a charm!
Thanks for all of your help!
-Dennis