简体   繁体   English

使用JdbcDatasource的上风报告问题

[英]An issue with windward reports using JdbcDatasource

I'm trying to use Windward reports for making a simple report. 我正在尝试使用Windward报告制作简单报告。 I use JdbcDataSorce object in order to connect Oracle database. 我使用JdbcDataSorce对象来连接Oracle数据库。 Here's the code: 这是代码:

package org.qrf.test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import net.windward.bean.BeanProviderException;
import net.windward.datasource.DatasetField;
import net.windward.datasource.jdbc.JdbcDataSource;
import net.windward.datasource.jdbc.JdbcDataset;
import net.windward.datasource.jdbc.JdbcDatasetField;
import net.windward.env.DataConnectionException;
import net.windward.env.DataSourceException;
import net.windward.env.OutputLimitationException;
import net.windward.format.TemplateParseException;
import net.windward.tags.TagException;
import net.windward.util.LicenseException;
import net.windward.xmlreport.AlreadyProcessedException;
import net.windward.xmlreport.ProcessReport;
import net.windward.xmlreport.ProcessRtf;
import net.windward.xmlreport.ProcessRtfAPI;
import net.windward.xmlreport.SetupException;

public class SQLDatasourcePrintTask {       
public static void main(String[] args) {
    Connection conn = null;
    try {
        Class.forName ("oracle.jdbc.OracleDriver");
        conn = DriverManager.getConnection(
                "jdbc:oracle:thin:@//localhost:1521/mybase", "scott", "tiger");
        JdbcDataSource ds = new JdbcDataSource(conn);

        ProcessReport.init();

        // объявление полей таблицы шаблона
        ArrayList<JdbcDatasetField> fields = new ArrayList<JdbcDatasetField>();
        fields.add(new JdbcDatasetField("SNAME_EDI", "VARCHAR2", "SNAME_EDI", null, DatasetField.TYPE_COLUMN));
        fields.add(new JdbcDatasetField("NAME_EDI",  "VARCHAR2", "NAME_EDI",  null, DatasetField.TYPE_COLUMN));
        fields.add(new JdbcDatasetField("ID_EDI",    "NUMBER",   "ID_EDI",    null, DatasetField.TYPE_COLUMN));
        fields.add(new JdbcDatasetField("CODE_EDI",  "NUMBER",   "CODE_EDI",  null, DatasetField.TYPE_COLUMN));
        // объявление набора данных
        JdbcDataset dataset = new JdbcDataset("SPR_EDI_DATASET", 
                "select se.id_edi, se.name_edi, se.sname_edi, se.code_edi " +
                "   from SPR_EDI se", "---", fields);
        // Объявление потоков
        InputStream in = new FileInputStream(new File("template/sql_template.rtf"));
        OutputStream out = new FileOutputStream(new File("sql_datasource_out.rtf"));            
        // объявление RTF-процессора
        ProcessRtfAPI process = new ProcessRtf(
                in, out);
        process.processSetup();
        // объявление карты переменных
        HashMap<String, Object> variablesMap = new HashMap<String, Object>();
        variablesMap.put("id_edi", 100);

        ds.setDatasets(new Object[]{dataset});                  
        ds.setMap(variablesMap);                        
        process.processData(ds, "SPR_EDI_DATASET");         
        process.processComplete();
        out.flush();
        in.close();
        out.close();
    } catch (ClassNotFoundException e) {            
        e.printStackTrace();
    } catch (SQLException e) {          
        e.printStackTrace();
    } catch (DataConnectionException e) {           
        e.printStackTrace();
    } catch (LicenseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SetupException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (TagException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (AlreadyProcessedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (DataSourceException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (BeanProviderException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (TemplateParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OutputLimitationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        try {
            conn.close();               
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

} }

I also use simple template created with an AutoTag tool 我还使用通过自动标记工具创建的简单模板 模板的例子

When I run this program it seems that connect to database is successful, but when I open the output file after finishing I get the same contents as in the picture above. 当我运行该程序时,似乎连接数据库成功,但是在完成后打开输出文件时,得到的内容与上图相同。 Please help me to solve this problem. 请帮我解决这个问题。

Generally when this happens the problem is your call: 通常,发生这种情况时,问题出在您的电话上:

process.processData(ds, "SPR_EDI_DATASET"); process.processData(ds,“ SPR_EDI_DATASET”);

uses the name "SPR_EDI_DATASET" but the tags in the template have a different name for the datasource. 使用名称“ SPR_EDI_DATASET”,但是模板中的标记的数据源名称不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM