简体   繁体   English

BIRT:如何从JavaScript访问当前的数据库连接/会话?

[英]BIRT: How can I access the current DB connections/session from JavaScript?

I need to run a piece of Java code which builds a complex SQL query. 我需要运行一段Java代码,以构建一个复杂的SQL查询。 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? 我知道如何从BIRT中的JavaScript调用Java方法,但是如何获得指向当前数据库会话/连接的指针?

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. 如果您修改数据集的onCreate事件,则可以在报表上执行此操作,并保留BIRT来控制数据库连接。 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 选择Eclipse画布区域下边缘的scripts选项卡
  3. Select the " onCreate " event from the drop-down list of available events along the top 从顶部的可用事件下拉列表中选择“ onCreate ”事件
  4. Work your query-building magic in the editor, using JavScript. 使用JavScript在编辑器中处理构建查询的魔术。 You can import your existing POJO that build your query out using the "Packages" construct. 您可以导入现有的POJO,以使用“包”结构构建查询。
  5. Once your POJO has built the query, return it to the script and set " this.queryText " equal to the resulting string. POJO建立查询后,将其返回到脚本并设置“ this.queryText ”等于结果字符串。

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. 如何填充各个列取决于SQL,结果数据集的外观必须统一。

Good Luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM