views:

22

answers:

1

I need to run a piece of Java code which builds a complex SQL query. I know how to call the Java methods from JavaScript in BIRT but how can I get a pointer to the current DB session/connection?

+1  A: 

If you modify the onCreate event of your Data Set, you can do this on the report and leave BIRT to control the DB connection. Do the following:

  1. Select your Data Set on the Data Explorer window
  2. Select the scripts tab along the lower edge of the canvas area of Eclipse
  3. Select the "onCreate" event from the drop-down list of available events along the top
  4. Work your query-building magic in the editor, using JavScript. You can import your existing POJO that build your query out using the "Packages" construct.
  5. Once your POJO has built the query, return it to the script and set "this.queryText" equal to the resulting string.

This will ensure the data set executes the new query, not the one used to create the data set.

The only gotcha to watch out for is that the query you set in the script must return the same number of columns and have each column be named the same as in the default configuration and share the same data type. How the individual colums get populated is up to the SQL, how the resulting data set looks must me uniform.

Good Luck!

MystikSpiral
Accepted: Correct answer to my question but the question was wrong :-)
Aaron Digulla