日期:2014-05-16  浏览次数:20539 次

关于birt报表输出时的JDBC连接和Script Data Source连接的设置

一个完整的birt的报表设计过程包括两部分:一是设计报表;二是运行和生成报表;

一、报表设计生成

报表设计生成就是生产一个报表的模板,及.rptdesign格式的文件(实际是一个xml文件的生成),这个过程包括了以下几个步骤:

1)生成数据源(datasource);2)生成数据集(dataset);3)生成报表设计

这个过程有很多的例子,比如birt官方的例子如下:

import java.io.IOException;
import java.util.ArrayList;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.DataItemHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.LabelHandle;
import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
import org.eclipse.birt.report.model.api.PropertyHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.RowHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.TableHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn;

import com.ibm.icu.util.ULocale;

/**
?* Dynamic Table BIRT Design Engine API (DEAPI) demo.
?*/

public class DECreateDynamicTable
{
??? ReportDesignHandle designHandle = null;
??? ElementFactory designFactory = null;
??? StructureFactory structFactory = null;???
?
??? public static void main( String[] args )
??? {
??????? try
??????? {
??????????? DECreateDynamicTable de = new DECreateDynamicTable();
??????????? ArrayList al = new ArrayList();
??????????? al.add("OFFICECODE");
??????????? al.add("CITY");
??????????? al.add("COUNTRY");
???????????
??????????? de.buildReport(al, "From Offices" );
??????? }
??????? catch ( IOException e )
??????? {
??????????? // TODO Auto-generated catch block
??????????? e.printStackTrace();
??????? }
??????? catch ( SemanticException e )
??????? {
??????????? // TODO Auto-generated catch block
??????????? e.printStackTrace();
??????? }
??? }

??? void buildDataSource( ) throws SemanticException
??? {

??????? OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource(
??????????????? "Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
??????? dsHandle.setProperty( "odaDriverClass",
??????????????? "org.eclipse.birt.report.data.oda.sampledb.Driver" );
??????? dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
??????? dsHandle.setProperty( "odaUser", "ClassicModels" );
??????? dsHandle.setProperty( "odaPassword", "" );
????????
??????
??????? designHandle.getDataSources( ).add( dsHandle );

??? }

??? void buildDataSet(ArrayList cols, String fromClause ) throws SemanticException
??? {

??????? OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
??????????????? "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
??????? dsHandle.setDataSource( "Data Source" );
??????? String qry = "Select ";
??????? for( int i=0; i < cols.size(); i++){
??????????? qry += " " + cols.get(i);
??????????? if( i != (cols.size() -1) ){
??????????????? qry += ",";
??????????? }<