Java 通过其API设置BIRT数据源

Java 通过其API设置BIRT数据源,java,jdbc,birt,Java,Jdbc,Birt,我正在寻找编写BIRT API w/a数据源的一些方向。我不确定如何配置我的应用程序以访问创建的数据源。如果我能得到这方面的帮助,那就太好了。我在这里。我已经通过BIRT RCP创建了一份报告。现在,我希望使用常规java应用程序和web应用程序生成报告。两者都将通过我将要创建的GUI传入日期参数。两者都需要有一个数据源。我在这里看到了一些使用报表设计器的示例,但是我没有使用它。我也没有使用BIRT报告创建者(RCP)GUI来生成这个 谢谢 import java.util.logging.Le

我正在寻找编写BIRT API w/a数据源的一些方向。我不确定如何配置我的应用程序以访问创建的数据源。如果我能得到这方面的帮助,那就太好了。我在这里。我已经通过BIRT RCP创建了一份报告。现在,我希望使用常规java应用程序和web应用程序生成报告。两者都将通过我将要创建的GUI传入日期参数。两者都需要有一个数据源。我在这里看到了一些使用报表设计器的示例,但是我没有使用它。我也没有使用BIRT报告创建者(RCP)GUI来生成这个

谢谢

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();
        }
    }
}

通过深入研究,我找到了我自己问题的解决方案,并想与大家分享答案

为了澄清这一点,我正在寻找一种方法将我的代码连接到
数据源
,以便运行我的
BIRT
报告查询。我发现,通过获取应用程序上下文,然后通过键值对设置在该对象中设置连接,可以通过
IGetParameterDefinitionTask
对象传入连接

请参见下面代码中的这一行。。。
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();
    }
}
}