Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[birt-dev] RE: About IDataExtractionTask question or issue, please help.

Hi, Chaohua

 

I think you code highlighted is not correct. I add comments in blue.

 

Thanks

 

Gang

 


From: Chaohua Wang [mailto:chaohua.wang@xxxxxxxxxxxxxxx]
Sent: Saturday, April 29, 2006 5:53 AM
To: Gang Liu; birt-dev@xxxxxxxxxxx
Subject: About IDataExtractionTask question or issue, please help.

 

Hi, Folks,

 

I use  IDataExtractionTask to extract result set, and want output CSV file.

My result set only shows EmployeeNumber and LastName, please see attached pdf file. The generated pdf file is perfect.

 

I got this result when I use iExtractResults.nextResultIterator( ) to print result set.

row["EMPLOYEENUMBER"] , row["LASTNAME"] ,

1002 , Patterson , null , null , null , null , null , null , null , null , null , null , null

 null , null ,

 

I am not sure what is wrong? Please help.

I expected result that should be like this:

----------------------------------------------------------------------------

 

EMPLOYEENUMBER, LASTNAME

1002, Murphy

1056, Patterson

1076, Firrelli

1088, Patterson

1102, Bondur

1143,Bow

1165, Jennings

1166, Thompson

1188, Firrelli

1216, Patterson

 

I use resultItem.getResultMetaData().getColumnName(i)  to print column’s name. But how do take row[ ] out without my coding.

 

 

The following is my code

 

public void  runDataExtraction()

        {

            try

            {

            //Open previously created report document

            IReportDocument iReportDocument = reportEngine.openReportDocument( docFile );

         

            //Create Data Extraction Task                

            IDataExtractionTask iDataExtract = reportEngine.createDataExtractionTask(iReportDocument);

                    

            //Get list of result sets               

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

           

            System.out.println("resultSetList " + resultSetList.size() );

           

             //Choose first result set

            IResultSetItem resultItem = (IResultSetItem)resultSetList.get( 0 );

            String dispName = resultItem.getResultSetName( );

                 

            iDataExtract.selectResultSet( dispName );

                        

            for (int i=0; i< resultItem.getResultMetaData().getColumnCount( ); i++)

            {

                System.out.print( resultItem.getResultMetaData().getColumnName(i) + " , " );

            }

           

            System.out.println("");

            IExtractionResults iExtractResults = iDataExtract.extract();               

                      

            IDataIterator iData = null;

              

             

               if ( iExtractResults != null )

               {

                    

                   iData = iExtractResults.nextResultIterator( );

                  

                       //iterate through the results

                        if ( iData != null  )

                        {

                            

                             int n = 0;

                             StringBuffer sb = new StringBuffer();

                             String new_pair = "";

 

                             while ( iData.next( ) )

                            {      

                                sb.append( new_pair );

                                                Object objColumn;

                                           

                                       try{

                                        objColumn = iData.getValue(n++);

                                        sb.append(objColumn);

                                        sb.append(" , ");

                                        }catch(Exception e){

                                                     objColumn = new String("");

                                }

 

                   Gang:                 IResultMetaData resultMeta = iExtractResults.getResultMetaData( );

                                                        for ( int i = 0; i < resultMeta.getColumnCount( ); i++ )

                                                        {

                                                                 objColumn = iData.getValue( resultMeta

                                                                                    .getColumnName( i ) );

                                                                 sb.append(objColumn);

                                                                 sb.append(" , ");

                                                        }

                                                        sb.append("\n");

                                               

                                         } 

                             System.out.println( sb.toString() );

                                                      

                             iData.close();

                        }

                        

               }

             

              iDataExtract.close();

        }catch( Exception e)

        {

                        e.printStackTrace();

        }

           

   }

 

 

 


Back to the top