如何以编程方式设置 BIRT 报告的数据源?
我有一个连接到我们的测试数据库的 BIRT 报告。在生产环境中,我想提供一个由容器通过 jndi 提供的数据源。
如何以编程方式为给定报告设置数据源?
...
IReportRunnable design = birtEngine.openReportDesign ( new File ( properties.getProperty ( "reportPath" ), report + ".rptdesign" ).getAbsolutePath () );
IRunAndRenderTask task = birtEngine.createRunAndRenderTask ( design );
PDFRenderOption options = new PDFRenderOption ();
options.setOutputFormat ( PDFRenderOption.OUTPUT_FORMAT_PDF );
options.setOutputStream ( out );
task.setRenderOption ( options );
for ( Entry<String, Object> entry : parameters.entrySet () )
{
task.setParameterValue ( entry.getKey (), entry.getValue () );
}
task.run ();
task.close ();
...
我想我必须修改 design
但另一方面 task
有一个方法 setDataSource
但这看起来有点像我必须提供一些 xml dom 元素。
I have a BIRT report which connects to our test database. In the productive environment I would like to supply a datasource which is provided by the container through jndi.
How would I set the datasource programmatically for the given report?
...
IReportRunnable design = birtEngine.openReportDesign ( new File ( properties.getProperty ( "reportPath" ), report + ".rptdesign" ).getAbsolutePath () );
IRunAndRenderTask task = birtEngine.createRunAndRenderTask ( design );
PDFRenderOption options = new PDFRenderOption ();
options.setOutputFormat ( PDFRenderOption.OUTPUT_FORMAT_PDF );
options.setOutputStream ( out );
task.setRenderOption ( options );
for ( Entry<String, Object> entry : parameters.entrySet () )
{
task.setParameterValue ( entry.getKey (), entry.getValue () );
}
task.run ();
task.close ();
...
I guess I would have to modify the design
but on the other hand task
has a method setDataSource
but that looks a bit like I would have to supply some xml dom elements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
查看以下代码,您可能会在运行时提供数据源方面获得一些帮助。
对于我的要求,它工作得很好。
我从某个网站得到这个不记得了。
Look at following code you may get some help in providing data source at runtime.
For my requirements it works fine.
I got this from some site do not remember.
您可以为数据库连接字符串创建报告参数。
然后,在Data Source -> 设置JNDI URL属性绑定-> JNDI URL,如:params["Database"].value
(其中“数据库”是报告参数的名称)
You can create a Report Parameter for the database connection string.
Then, set the JNDI URL under Data Source -> Property Binding -> JNDI URL, as: params["Database"].value
(Where "Database" is the name of the report parameter)
在运行时仅设置数据源将会出现问题,因为数据集绑定到单个数据源,并且报表上的控件随后绑定到特定数据集。每次运行报表时,尝试自行构建此层次结构将非常困难。
您可以参数化数据源定义的所有方面,使您的设计可在所有环境中移植。编辑数据源时,请查看左侧的属性绑定分组。这将为您提供足够的灵活性,使您的数据源更加可移植。您可以为 JDBC URL 元素或运行时 JNDI 配置文件指定运行时参数。
希望这有帮助。
Setting just the data source at run-time will be problematic because the data set is bound to a single data source and your controls on the report are then bound to a specific data set. This hierarchy would be pretty sticky to try and build yourself each time the report runs.
You can parameterize all aspects of the Data Source definition making your design portable through all environments. When editing your Data Source, look at the Property Binding grouping on the left hand side. This should give you ample flexibility to make your data source more portable. You can specify run-time parameters for JDBC URL elements or a run-time JNDI profile.
Hope this helps.
我喜欢亚当斯的方法。
我们是这样做的:
这里,“lisa”是我们要在运行时更改的数据源的名称。
get... 函数返回“生产”运行时所需的值。
I like Adams approach.
Here's how we do it:
Here, "lisa" ist he name of the datasource we would like to change at runtime.
The get... function return the values needed at "production" run time.
这对我有用。我获取了上下文,并从上下文中获取了数据源并将连接传递给 Birt 报告,如下所示
This worked for me. I got the context and from context got the dataSource and passed the connection to Birt report like below