通过其API设置BIRT数据源 - java

我正在寻找使用数据源对BIRT API进行编码的方向。我不确定如何配置我的应用程序以访问创建的数据源。如果我可以得到一些帮助,那就太好了。我在这里我已经通过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();
        }
    }
}

参考方案

经过更深入的研究,我找到了自己问题的解决方案,并认为我会分享答案。

为了明确起见,我正在寻找一种将代码连接到datasource的方法,因此我的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();
    }
}
}

Java Double与BigDecimal - java

我正在查看一些使用双精度变量来存储(360-359.9998779296875)结果为0.0001220703125的代码。 double变量将其存储为-1.220703125E-4。当我使用BigDecimal时,其存储为0.0001220703125。为什么将它双重存储为-1.220703125E-4? 参考方案 我不会在这里提及精度问题,而只会提及数字…

java:继承 - java

有哪些替代继承的方法? java大神给出的解决方案 有效的Java:偏重于继承而不是继承。 (这实际上也来自“四人帮”)。他提出的理由是,如果扩展类未明确设计为继承,则继承会引起很多不正常的副作用。例如,对super.someMethod()的任何调用都可以引导您通过未知代码的意外路径。取而代之的是,持有对本来应该扩展的类的引用,然后委托给它。这是与Eric…

Java:BigInteger,如何通过OutputStream编写它 - java

我想将BigInteger写入文件。做这个的最好方式是什么。当然,我想从输入流中读取(使用程序,而不是人工)。我必须使用ObjectOutputStream还是有更好的方法?目的是使用尽可能少的字节。谢谢马丁 参考方案 Java序列化(ObjectOutputStream / ObjectInputStream)是将对象序列化为八位字节序列的一种通用方法。但…

Java-如何将此字符串转换为日期? - java

我从服务器收到此消息,我不明白T和Z的含义,2012-08-24T09:59:59Z将此字符串转换为Date对象的正确SimpleDateFormat模式是什么? java大神给出的解决方案 这是ISO 8601标准。您可以使用SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM…

Java:从类中查找项目名称 - java

仅通过类的实例,如何使用Java反射或类似方法查找项目名称?如果不是,项目名称(我真正想要的是)可以找到程序包名称吗? 参考方案 项目只是IDE使用的简单组织工具,因此项目名称不是类或JVM中包含的信息。要获取软件包,请使用Class#getPackage()。然后,可以调用Package#getName()将包作为您在代码的包声明中看到的String来获取…