通过其API设置BIRT数据源 [英] Setting BIRT datasource through its API
问题描述
我正在寻找编码带有数据源的BIRT API的方向。我不确定如何配置我的应用程序来访问创建的数据源。如果我能得到一些帮助,那就太好了。这就是我。我已经通过BIRT RCP创建了一份报告。现在我想使用常规Java应用程序和Web应用程序生成报告。两者都将通过我将要创建的GUI传递日期参数。两者都需要有数据源。我已经看到一些使用报表设计器的示例,但我没有使用它。我也没有使用BIRT Report Creator(RCP)GUI来生成它。
I'm looking for some direction for coding the BIRT API w/ a datasource. I'm unsure of how to configure my application to access a created datasource. If I can get some help w/this it would be great. Here's where I am. I've already created a report through BIRT RCP. Now I'm looking to generate the report using a regular java application AND a web application. Both will be passing in date parameters through a GUI that I'll be creating. Both need to have a datasource. I've have seen some examples here that use the Report Designer however I am not using that. I'm also NOT using the BIRT Report Creator (RCP) GUI to generate this.
谢谢
import java.util.logging.Level;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
public class ReportGenerator {
public static void main(String args[]) throws EngineException {
ReportGenerator reportGenerator = new ReportGenerator();
reportGenerator.executeReport();
}
public void executeReport() throws EngineException {
IReportEngine engine=null;
EngineConfig config = null;
try{
config = new EngineConfig( );
config.setBIRTHome("C:\\birt-rcp-report-designer-3_7_2\\ReportEngine");
config.setLogConfig("c:/temp/test", Level.FINEST);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
IReportRunnable design = null;
//Open the report design
design = engine.openReportDesign("ReportTemplates/testNoData.rptdesign");
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
task.setParameterValue("AuthorName", "Dale DeMott");
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFileName("output/resample/Parmdisp.html");
options.setOutputFormat("html");
task.setRenderOption(options);
//Looking to create and insert a datasource here.
//task.setDataSource(some parameters here that represent the ds);
task.run();
task.close();
engine.destroy();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
Platform.shutdown();
}
}
}
推荐答案
深入研究我找到了解决自己问题的方法,并认为我会分享答案。
Researching this deeper I found the solution to my own question and thought I'd share the answer.
为了澄清我正在寻找一种方法将我的代码连接到数据源
,所以我的 BIRT
报告查询将运行。我发现,我可以通过获取应用程序上下文然后通过键值对设置在此对象中设置连接,通过 IGetParameterDefinitionTask
对象传递连接。
To clarify I was looking for a way to connect my code to a datasource
, so my BIRT
report queries would run. I found that, I can pass in a connection via the IGetParameterDefinitionTask
object by getting the application context then setting the connection in this object through a key value pair setting.
在下面的代码中查看此行...
task.getAppContext()。put(OdaJDBCDriverPassInConnection,conn);
See this line in the code below...
task.getAppContext().put("OdaJDBCDriverPassInConnection", conn);
public class ReportGenerator {
public static void main(String args[]) throws EngineException {
ReportGenerator reportGenerator = new ReportGenerator();
reportGenerator.executeReport();
}
public void executeReport() throws EngineException {
IReportEngine engine=null;
EngineConfig config = null;
try{
config = new EngineConfig( );
config.setBIRTHome("C:\\birt-rcp-report-designer-3_7_2\\ReportEngine");
config.setLogConfig("c:/temp/test", Level.FINEST);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
IReportRunnable design = null;
//Open the report design
design = engine.openReportDesign("ReportTemplates/testNoData.rptdesign");
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
task.setParameterValue("AuthorName", "Dale DeMott");
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFileName("output/resample/Parmdisp.html");
options.setOutputFormat("html");
task.setRenderOption(options);
//Connection helper is a utility class used to create a connection to your
//database and return it.
ConnectionHelper connectionHelper = new ConnectionHelper();
Connection conn = connectionHelper.getConnection();
task.getAppContext().put("OdaJDBCDriverPassInConnection", conn);
task.run();
task.close();
engine.destroy();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
Platform.shutdown();
}
}
}
这篇关于通过其API设置BIRT数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!