0

我在我的 java 应用程序中连接到 db2 数据库时遇到困难。我在网上找到了一些示例,但作为 java 新手,我无法成功应用它们。我的尝试如下。基本上,我的程序只是在 datafactory 方法中从数据库中提取数据,然后生成一个 html 报告。

package org.pentaho.reporting.engine.classic.samples;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import org.pentaho.reporting.engine.classic.core.DataFactory;
import org.pentaho.reporting.engine.classic.core.MasterReport;
import org.pentaho.reporting.engine.classic.core.ReportProcessingException;
import org.pentaho.reporting.engine.classic.core.PageDefinition;
import org.pentaho.reporting.engine.classic.core.wizard.RelationalAutoGeneratorPreProcessor;
import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SQLReportDataFactory;
import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.DriverConnectionProvider;

public class report2013HTML extends AbstractReportGenerator
{
  private static final String QUERY_NAME = "ReportQuery";

  /**
   * Default constructor for this sample report generator
   */
  public report2013HTML()
  {
  }  
    * @return the loaded and parsed report definition to be used in report generation.
       */
      public MasterReport getReportDefinition()
      {
        final MasterReport report = new MasterReport();
        report.setQuery(QUERY_NAME);
        report.addPreProcessor(new RelationalAutoGeneratorPreProcessor());
        return report;
      }

          public DataFactory getDataFactory()
          {
            final DriverConnectionProvider sampleDriverConnectionProvider = new DriverConnectionProvider();
            sampleDriverConnectionProvider.setDriver("com.ibm.db2.jcc.DB2Driver");
            sampleDriverConnectionProvider.setUrl("jdbc:db2://hostname:1000/database");
            sampleDriverConnectionProvider.setProperty("user", "user");
            sampleDriverConnectionProvider.setProperty("password", "pass");

            final SQLReportDataFactory dataFactory = new SQLReportDataFactory(sampleDriverConnectionProvider);
            dataFactory.setQuery(QUERY_NAME,
                "select project_name FROM fact_table");

            return dataFactory;
          }

之后,还有最后一种方法可以生成 HTML 文件。显然,在一些连接错误中,我收到了一个报告处理失败错误。

    Exception in thread "main" org.pentaho.reporting.engine.classic.core.ReportProcessingException: Unable to initialize the report
    at org.pentaho.reporting.engine.classic.core.layout.output.AbstractReportProcessor.prepareReportProcessing(AbstractReportProcessor.java:563)
    at org.pentaho.reporting.engine.classic.core.layout.output.AbstractReportProcessor.processReport(AbstractReportProcessor.java:1412)
    at org.pentaho.reporting.engine.classic.samples.AbstractReportGenerator.generateReport(AbstractReportGenerator.java:218)
    at org.pentaho.reporting.engine.classic.samples.AbstractReportGenerator.generateReport(AbstractReportGenerator.java:128)
    at org.pentaho.reporting.engine.classic.samples.mira2013HTML.main(mira2013HTML.java:103)
ParentException: 
org.pentaho.reporting.engine.classic.core.ReportDataFactoryException: Failed at query: select project_name FROM fact_table
    at org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SimpleSQLReportDataFactory.queryData(SimpleSQLReportDataFactory.java:270)
    at org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SQLReportDataFactory.queryData(SQLReportDataFactory.java:95)
    at org.pentaho.reporting.engine.classic.core.states.CachingDataFactory.queryInternal(CachingDataFactory.java:176)
    at org.pentaho.reporting.engine.classic.core.states.CachingDataFactory.queryData(CachingDataFactory.java:144)
    at org.pentaho.reporting.engine.classic.core.states.CascadingDataFactory.queryData(CascadingDataFactory.java:110)
    at org.pentaho.reporting.engine.classic.core.states.datarow.ReportDataRow.createDataRow(ReportDataRow.java:97)
    at org.pentaho.reporting.engine.classic.core.states.datarow.DefaultFlowController.performQuery(DefaultFlowController.java:189)
    at org.pentaho.reporting.engine.classic.core.states.process.ProcessState.<init>(ProcessState.java:279)
    at org.pentaho.reporting.engine.classic.core.layout.output.AbstractReportProcessor.prepareReportProcessing(AbstractReportProcessor.java:463)
    at org.pentaho.reporting.engine.classic.core.layout.output.AbstractReportProcessor.processReport(AbstractReportProcessor.java:1412)
    at org.pentaho.reporting.engine.classic.samples.AbstractReportGenerator.generateReport(AbstractReportGenerator.java:218)
    at org.pentaho.reporting.engine.classic.samples.AbstractReportGenerator.generateReport(AbstractReportGenerator.java:128)
    at org.pentaho.reporting.engine.classic.samples.report2013HTML.main(report2013HTML.java:103)
ParentException: 
java.sql.SQLException: Unable to load the driver: com.ibm.db2.jcc.DB2Driver
    at org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.DriverConnectionProvider.createConnection(DriverConnectionProvider.java:102)
    at org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SimpleSQLReportDataFactory.getConnection(SimpleSQLReportDataFactory.java:184)
    at org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SimpleSQLReportDataFactory.queryData(SimpleSQLReportDataFactory.java:255)
    at org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SQLReportDataFactory.queryData(SQLReportDataFactory.java:95)
    at org.pentaho.reporting.engine.classic.core.states.CachingDataFactory.queryInternal(CachingDataFactory.java:176)
    at org.pentaho.reporting.engine.classic.core.states.CachingDataFactory.queryData(CachingDataFactory.java:144)
    at org.pentaho.reporting.engine.classic.core.states.CascadingDataFactory.queryData(CascadingDataFactory.java:110)
    at org.pentaho.reporting.engine.classic.core.states.datarow.ReportDataRow.createDataRow(ReportDataRow.java:97)
    at org.pentaho.reporting.engine.classic.core.states.datarow.DefaultFlowController.performQuery(DefaultFlowController.java:189)
    at org.pentaho.reporting.engine.classic.core.states.process.ProcessState.<init>(ProcessState.java:279)
    at org.pentaho.reporting.engine.classic.core.layout.output.AbstractReportProcessor.prepareReportProcessing(AbstractReportProcessor.java:463)
    at org.pentaho.reporting.engine.classic.core.layout.output.AbstractReportProcessor.processReport(AbstractReportProcessor.java:1412)
    at org.pentaho.reporting.engine.classic.samples.AbstractReportGenerator.generateReport(AbstractReportGenerator.java:218)
    at org.pentaho.reporting.engine.classic.samples.AbstractReportGenerator.generateReport(AbstractReportGenerator.java:128)
    at org.pentaho.reporting.engine.classic.samples.report2013HTML.main(report_HTML.java:103)
4

0 回答 0