简体   繁体   中英

An issue with windward reports using JdbcDatasource

I'm trying to use Windward reports for making a simple report. I use JdbcDataSorce object in order to connect Oracle database. 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");

uses the name "SPR_EDI_DATASET" but the tags in the template have a different name for the datasource.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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