Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Data Extract (BIRT) 2.1"

(New page: {{Backlink|Integration Examples (BIRT)}} == Data Extract == This example demonstrates using the RE API to run a report and extract the results from the rptdocument. Add comments at the ...)
 
(DataExtract.java)
Line 90: Line 90:
 
   //Iterate the results
 
   //Iterate the results
 
   try{
 
   try{
   if ( iExtractResults != null )
+
   if ( iExtractResults != null ) {
  {
+
    iData = iExtractResults.nextResultIterator( );
    iData = iExtractResults.nextResultIterator( );
+
    if ( iData != null  ){
    //Get metadata on retrieved results
+
      //Get metadata on retrieved results
    IResultMetaData irmd = iData.getResultMetaData();
+
      IResultMetaData irmd = iData.getResultMetaData();
    if ( iData != null  ){
+
      int colCount = irmd.getColumnCount();
    int colCount = irmd.getColumnCount();
+
      System.out.println("Cloumn Count =" + colCount );
    System.out.println("Cloumn Count =" + colCount );
+
      for( int j=0; j< colCount; j++){
    for( int j=0; j< colCount; j++){
+
        System.out.println("Cloumn Name =" + irmd.getColumnName(j) );
      System.out.println("Cloumn Name =" + irmd.getColumnName(j) );
+
        System.out.println("Cloumn Type =" + irmd.getColumnTypeName(j) );
      System.out.println("Cloumn Type =" + irmd.getColumnTypeName(j) );
+
      }
    }
+
 
   
 
   
    while ( iData.next( ) )
+
      while ( iData.next( ) ) {  
    {  
+
        //Just disply the first two columns
      //Just disply the first two columns
+
        Object objColumn1;
      Object objColumn1;
+
        Object objColumn2;
      Object objColumn2;
+
        try{
      try{
+
          objColumn1 = iData.getValue(0);
      objColumn1 = iData.getValue(0);
+
        } catch(DataException e) {
      }catch(DataException e){
+
          objColumn1 = new String("");
      objColumn1 = new String("");
+
        }
      }
+
     
      try{
+
        try{
      objColumn2 = iData.getValue(1);
+
          objColumn2 = iData.getValue(1);
      }catch(DataException e){
+
        } catch(DataException e){
      objColumn2 = new String("");
+
          objColumn2 = new String("");
      }
+
        }  
      System.out.println( objColumn1 + " , " + objColumn2 );
+
       
 +
        System.out.println( objColumn1 + " , " + objColumn2 );
 +
      }
 +
      iData.close();
 
     }
 
     }
    iData.close();
 
    }
 
 
   }
 
   }
 
   }catch( Exception e){
 
   }catch( Exception e){
Line 129: Line 129:
 
   //Note - If the program stays resident do not shutdown the Platform or the Engine   
 
   //Note - If the program stays resident do not shutdown the Platform or the Engine   
 
   iDataExtract.close();
 
   iDataExtract.close();
   engine.shutdown();
+
   engine.destroy();
 
   Platform.shutdown();
 
   Platform.shutdown();
 
   System.out.println("Finished");
 
   System.out.println("Finished");

Revision as of 17:51, 20 June 2008

< To: Integration Examples (BIRT)

Data Extract

This example demonstrates using the RE API to run a report and extract the results from the rptdocument.

Add comments at the bottom of the example.

BIRT Report Engine API Return to the BIRT Report Engine API examples

Source

DataExtract.java

import java.util.ArrayList;
import java.util.logging.Level;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.data.engine.core.DataException;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.IDataExtractionTask;
import org.eclipse.birt.report.engine.api.IDataIterator;
import org.eclipse.birt.report.engine.api.IExtractionResults;
import org.eclipse.birt.report.engine.api.IReportDocument;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IResultMetaData;
import org.eclipse.birt.report.engine.api.IResultSetItem;
import org.eclipse.birt.report.engine.api.IRunTask;


public class DataExtract {

static void executeReport() throws EngineException
{
 IReportEngine engine=null;
 EngineConfig config = null;
 try{
  config = new EngineConfig( );
  config.setEngineHome( "C:\eclipseBIRT\eclipse\features\org.eclipse.birt.report.runtime_2.2.0.v20070529-7U7U-Cmz0UWCVvy52" );
  config.setLogConfig(null, Level.FINE);

  Platform.startup( config );
  IReportEngineFactory factory = (IReportEngineFactory) Platform
  .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
  engine = factory.createReportEngine( config );
  engine.changeLogLevel( Level.WARNING );

 }catch( Exception ex){
  ex.printStackTrace();
 }

 //open the report design
 IReportRunnable design = null;

 design = engine.openReportDesign("C:/temp/BIRT/acceptandorder.rptdesign"); 

 //Create task to run the report - use the task to run the report,
 IRunTask task = engine.createRunTask(design); 

 //Run the report and create the rptdocument
 task.run("C:/temp/BIRT/acceptandorder.rptdocument");

 //Open the rptdocument
 IReportDocument rptdoc = engine.openReportDocument("C:/temp/BIRT/acceptandorder.rptdocument"); 

 //Create the data extraction task
 IDataExtractionTask iDataExtract = engine.createDataExtractionTask(rptdoc);

 /**
  * returns the metadata corresponding to the data stored in the report
  * document.  Could specify a component.
  */

 ArrayList resultSetList = (ArrayList)iDataExtract.getResultSetList( );

 //Get the first result set.  Note this is a table elemenent
 IResultSetItem resultItem = (IResultSetItem)resultSetList.get( 0 );

 //Set the name of the element you want to retrieve.  
 //This will usually be ELEMENT_something if you do not name your elements.
 //If you name a table for example "MyTable"  this will be the resultset name
 String dispName = resultItem.getResultSetName( );
 iDataExtract.selectResultSet( dispName );

 IExtractionResults iExtractResults = iDataExtract.extract();
 IDataIterator iData = null;

 //Iterate the results
 try{
  if ( iExtractResults != null ) {
    iData = iExtractResults.nextResultIterator( );
    if ( iData != null  ){
      //Get metadata on retrieved results
      IResultMetaData irmd = iData.getResultMetaData();
      int colCount = irmd.getColumnCount();
      System.out.println("Cloumn Count =" + colCount );
      for( int j=0; j< colCount; j++){
        System.out.println("Cloumn Name =" + irmd.getColumnName(j) );
        System.out.println("Cloumn Type =" + irmd.getColumnTypeName(j) );
      }

      while ( iData.next( ) ) { 
        //Just disply the first two columns
        Object objColumn1;
        Object objColumn2;
        try{
          objColumn1 = iData.getValue(0);
        } catch(DataException e) {
          objColumn1 = new String("");
        }
      
        try{
          objColumn2 = iData.getValue(1);
        } catch(DataException e){
          objColumn2 = new String("");
        } 
        
        System.out.println( objColumn1 + " , " + objColumn2 );
      }
      iData.close();
    }
  }
 }catch( Exception e){
  e.printStackTrace();
 }
 //close the task and showdown the engine and Platform
 //Note - If the program stays resident do not shutdown the Platform or the Engine  
 iDataExtract.close();
 engine.destroy();
 Platform.shutdown();
 System.out.println("Finished");
}


public static void main(String[] args) {
 try
 {
  executeReport( );
 }
 catch ( Exception e )
 {
  e.printStackTrace();
 }
}

}

Comments

Please enter comments below by selecting the edit icon to the right. You will need a Bugzilla account to add comments.


This code is working for only first time. While running second time if we use same *. Rptdesign file its giving fallowing invalid design file error message. If we use new *. Rptdesign file then it will work fine. Means the code is modifying Rptdesign file. Can you please tell me how to solve this problem?


SEVERE: Line Number:1 Error Code:Error.XMLParserException.SAX_ERROR Exception:org.xml.sax.SAXParseException: Content is not allowed in prolog. Message:SAX detected an error with the basic XML syntax of the file. Jun 6, 2007 9:57:55 AM org.eclipse.birt.report.engine.api.impl.ReportEngineHelper openReportDesign SEVERE: invalid design file file:/D:/workspace/Simple/ZZZZ.rptdesign org.eclipse.birt.report.engine.api.EngineException: The design file file:/D:/workspace/Simple/ZZZZ.rptdesign has error and can not be run. at org.eclipse.birt.report.engine.api.impl.ReportEngineHelper.openReportDesign(ReportEngineHelper.java:249) at org.eclipse.birt.report.engine.api.impl.ReportEngineHelper.openReportDesign(ReportEngineHelper.java:192) at org.eclipse.birt.report.engine.api.impl.ReportEngineHelper.openReportDesign(ReportEngineHelper.java:126) at org.eclipse.birt.report.engine.api.impl.ReportEngine.openReportDesign(ReportEngine.java:222) at SRC.ReportGenerator.saveCSVFormat(ReportGenerator.java:314) at SRC.ReportGenerator.widgetSelected(ReportGenerator.java:240) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:90) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968) at SRC.ReportGenerator.runDemo(ReportGenerator.java:210) at SRC.ReportGenerator.main(ReportGenerator.java:94) Caused by: Error.DesignFileException.INVALID_XML - 2 errors found! 1.) ( line = 1, tag = null) org.eclipse.birt.report.model.util.XMLParserException (code = Error.XMLParserException.SAX_ERROR, message : Line Number:1 Error Code:Error.XMLParserException.SAX_ERROR Exception:org.xml.sax.SAXParseException: Content is not allowed in prolog. Message:SAX detected an error with the basic XML syntax of the file. ) 2.) ( line = 1) org.xml.sax.SAXParseException (message : Content is not allowed in prolog.)

at org.eclipse.birt.report.model.parser.ModuleReader.readModule(ModuleReader.java:117) at org.eclipse.birt.report.model.parser.DesignReader.read(DesignReader.java:90) at org.eclipse.birt.report.model.core.DesignSession.openDesign(DesignSession.java:301) at org.eclipse.birt.report.model.api.SessionHandle.openDesign(SessionHandle.java:292) at org.eclipse.birt.report.engine.parser.ReportParser.getDesignHandle(ReportParser.java:157) at org.eclipse.birt.report.engine.api.impl.ReportEngineHelper.openReportDesign(ReportEngineHelper.java:244) ... 12 more


Comments

Please enter comments below by selecting the edit icon to the right. You will need a Bugzilla account to add comments.


Back to the top