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:
- Select your Data Set on the Data Explorer window
- Select the scripts tab along the lower edge of the canvas area of Eclipse
- Select the "
onCreate
" event from the drop-down list of available events along the top - 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.
- 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
2010-10-13 16:36:29
Accepted: Correct answer to my question but the question was wrong :-)
Aaron Digulla
2010-10-14 09:04:19