我正在尝试使用 Windward 报告来制作简单的报告。我使用 JdbcDataSorce 对象来连接 Oracle 数据库。这是代码:
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();
}
}
}
}
我还使用使用 AutoTag 工具创建的简单模板
当我运行这个程序时,似乎连接到数据库是成功的,但是当我完成后打开输出文件时,我得到的内容与上图相同。请帮我解决这个问题。