<div>Hi Everyone, </div><div> </div><div>I was trying to run the below mentioned program, but i was not aware on how to configure the database used in this program and the drivers </div><div>could you please help me in doing this .</div><div> </div><div>I was trying this program in eclipse, but no impact </div><div>firstly i need to know how i need to configure the database or how i should connect to the database</div><div> </div><div>Please hellp me out.</div><div> </div><div>import java.io.IOException;</div><div>import java.util.ArrayList; </div><div> </div><div>import org.eclipse.birt.core.framework.Platform;</div><div>import org.eclipse.birt.report.model.api.CellHandle;</div><div>import org.eclipse.birt.report.model.api.DataItemHandle;</div><div>import org.eclipse.birt.report.model.api.DesignConfig; </div><div>import org.eclipse.birt.report.model.api.ElementFactory;</div><div>import org.eclipse.birt.report.model.api.IDesignEngine;</div><div>import org.eclipse.birt.report.model.api.IDesignEngineFactory;</div><div>import org.eclipse.birt.report.model.api.LabelHandle;</div><div>import org.eclipse.birt.report.model.api.OdaDataSetHandle;</div><div>import org.eclipse.birt.report.model.api.OdaDataSourceHandle;</div><div>import org.eclipse.birt.report.model.api.PropertyHandle;</div><div>import org.eclipse.birt.report.model.api.ReportDesignHandle;</div><div>import org.eclipse.birt.report.model.api.RowHandle;</div><div>import org.eclipse.birt.report.model.api.SessionHandle;</div><div>import org.eclipse.birt.report.model.api.SlotHandle;</div><div>import org.eclipse.birt.report.model.api.StructureFactory;</div><div>import org.eclipse.birt.report.model.api.TextItemHandle;</div><div>import org.eclipse.birt.report.model.api.TableHandle;</div><div>import org.eclipse.birt.report.model.api.ListHandle;</div><div>import org.eclipse.birt.report.model.api.SharedStyleHandle;</div><div>import org.eclipse.birt.report.model.api.activity.SemanticException;</div><div>import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn;</div><div>import org.eclipse.birt.report.model.api.StyleHandle;</div><div>import org.eclipse.birt.report.model.api.elements.structures.HighlightRule;</div><div> </div><div>import com.ibm.icu.util.ULocale;</div><div> </div><div>import org.eclipse.birt.report.model.api.elements.DesignChoiceConstants;</div><div> </div><div>/**</div><div> * Use the Design Engine API (model api) to design a report instead of the </div><div> * BIRT designer. This class will generate a similar report as </div><div> * derby_sample.rptdesign that was created using the Eclipse BIRT designer.</div><div> */</div><div>public class DerbySampleDE</div><div>{</div><div>ReportDesignHandle designHandle = null;</div><div>ElementFactory designFactory = null;</div><div>StructureFactory structFactory = null;<span> </span></div><div> </div><div>public static SessionHandle setup()</div><div>{</div><div> </div><div>//Configure the Engine and start the Platform</div><div>DesignConfig config = new DesignConfig( );</div><div>config.setProperty("BIRT_HOME", System.getProperty("BIRT_HOME"));</div><div>IDesignEngine engine = null;</div><div>try{</div><div>Platform.startup( config );</div><div>IDesignEngineFactory factory = (IDesignEngineFactory) Platform</div><div>.createFactoryObject( IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );</div><div>engine = factory.createDesignEngine( config );</div><div> </div><div>}catch( Exception ex){</div><div>ex.printStackTrace();</div><div>}<span> </span></div><div>SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;</div><div>return session;</div><div>}</div><div> </div><div>public static ReportDesignHandle createReport(SessionHandle session)</div><div>{</div><div>// create a design or a template</div><div>ReportDesignHandle reportDesignHandle = session.createDesign();</div><div> </div><div>return reportDesignHandle;</div><div>}</div><div> </div><div> </div><div> </div><div>public static void main( String[] args )</div><div>{</div><div>try</div><div>{</div><div>String qry = "select SAMP.DEPARTMENT.DEPTNAME,SAMP.EMPLOYEE.FIRSTNME,SAMP.EMPLOYEE.LASTNAME,SAMP.EMPLOYEE.JOB,CHAR(SAMP.EMPLOYEE.HIREDATE) as Hiredate,SAMP.EMPLOYEE.SALARY,SAMP.EMPLOYEE.BONUS,SAMP.EMPLOYEE.COMM"+</div><div>" from SAMP.EMPLOYEE, SAMP.DEPARTMENT where SAMP.DEPARTMENT.DEPTNO = SAMP.EMPLOYEE.WORKDEPT order by SAMP.DEPARTMENT.DEPTNAME";</div><div>String dataSourceName = "Sample Derby";</div><div>String dataSetName ="Sample Derby Data Set";</div><div> </div><div>SessionHandle session = setup();</div><div>ReportDesignHandle reportDesignHandle = createReport(session);</div><div> </div><div>addDataSource(reportDesignHandle,dataSourceName,"org.apache.derby.jdbc.EmbeddedDriver","jdbc:derby:C:/birt/demo/sample","APP","PWD");</div><div>buildDataSet(reportDesignHandle,dataSetName,dataSourceName,qry);</div><div> </div><div>ElementFactory elementFactory = reportDesignHandle.getElementFactory();</div><div> </div><div>// Create Styles.</div><div>StyleHandle labelStyle = elementFactory.newStyle( "headerLabel" );</div><div>labelStyle.setProperty( StyleHandle.FONT_WEIGHT_PROP,</div><div>DesignChoiceConstants.FONT_WEIGHT_BOLD );</div><div>labelStyle.setProperty( StyleHandle.FONT_FAMILY_PROP, "Andalus" );</div><div>labelStyle.setProperty( StyleHandle.COLOR_PROP, "red" );</div><div>labelStyle.setProperty( StyleHandle.BACKGROUND_COLOR_PROP,"aqua");</div><div>labelStyle.setProperty( StyleHandle.FONT_SIZE_PROP,"larger" );</div><div>labelStyle.setProperty( StyleHandle.COLOR_PROP, "red" );//$NON-NLS-1$</div><div>reportDesignHandle.getStyles( ).add( labelStyle );</div><div> </div><div> </div><div>StyleHandle detailStyle = elementFactory.newStyle( "detailStyle" );</div><div>detailStyle.setProperty( StyleHandle.FONT_WEIGHT_PROP,</div><div>DesignChoiceConstants.FONT_WEIGHT_BOLD );</div><div>detailStyle.setProperty( StyleHandle.BACKGROUND_COLOR_PROP,"#C0C0C0");</div><div>detailStyle.setProperty( StyleHandle.TEXT_ALIGN_PROP,"center");</div><div>PropertyHandle highlightRules = detailStyle.getPropertyHandle("highlightRules");</div><div> </div><div> </div><div>HighlightRule rules = StructureFactory.createHighlightRule();</div><div>rules.setOperator("eq");</div><div>rules.setProperty("backgroundColor","#80FFFF");</div><div>rules.setTestExpression("Total.runningCount() % 2");</div><div>rules.setValue1("0");</div><div>highlightRules.addItem(rules);</div><div>reportDesignHandle.getStyles( ).add( detailStyle );</div><div>StyleHandle dateStyle = elementFactory.newStyle( "dateStyle" );</div><div>dateStyle.setDateTimeFormat("DD_MM_YYYY");</div><div>dateStyle.setDateTimeFormatCategory("Medium Date");</div><div>//dateStyle.setD</div><div>reportDesignHandle.getStyles( ).add( dateStyle );</div><div> </div><div> </div><div>TextItemHandle text = elementFactory.newTextItem("text");</div><div>text.setContent("Employee Report");</div><div>reportDesignHandle.getComponents().add(text);</div><div> </div><div>// create a new table in the report with 5 columns</div><div>TableHandle table = elementFactory.newTableItem( "table", 5 );</div><div>table.setWidth( "100%" );</div><div> </div><div>// associate the dataset for this table</div><div>table.setDataSet( reportDesignHandle.findDataSet(dataSetName ) );</div><div> </div><div>// columns that are retrieved as part of the query in dataset</div><div>String[] cols ={</div><div>"DEPTNAME",</div><div>"FIRSTNME",</div><div>"LASTNAME",</div><div>"JOB",</div><div>"HIREDATE",</div><div>"SALARY",</div><div>"BONUS",</div><div>"COMM"</div><div>};</div><div> </div><div>// columns that are used in the report</div><div>String[][] reportCols ={</div><div>{"DEPTNAME","Dept Name"},</div><div>{"LASTNAME","Last Name"},</div><div>{"JOB","Job"},</div><div>{"HIREDATE","Hire Date"},</div><div>{"Total Income","Total Income"}</div><div>};</div><div> </div><div>// Set Column Bindings</div><div>PropertyHandle computedSet = table.getColumnBindings( ); </div><div>ComputedColumn cs1 = null;</div><div> </div><div>// DEPTNAME expression.</div><div>cs1 = StructureFactory.createComputedColumn();</div><div>cs1.setName(reportCols[0][0]);</div><div>cs1.setExpression("var newOutput = dataSetRow["DEPTNAME"].substr(0,1);"+</div><div>"var input = dataSetRow["DEPTNAME"].substr(1).toLowerCase();"+</div><div>"var j;"+</div><div>"for(i = 0;i<=input.length; i++) {"+</div><div>"if(input.charAt(i)==" ") {"+</div><div>"newOutput = newOutput + input.charAt(i) + input.charAt(i+1).toUpperCase();"+</div><div>"j = i + 1;"+</div><div>"}else {if(i!=j) {newOutput = newOutput + input.charAt(i);}}}newOutput;");</div><div>computedSet.addItem(cs1);</div><div> </div><div>for( int i=1; i < cols.length; i++){</div><div>cs1 = StructureFactory.createComputedColumn();</div><div>cs1.setName(cols
);</div><div>cs1.setExpression("dataSetRow["" + cols[i] + ""]");</div><div>computedSet.addItem(cs1);</div><div>}</div><div> </div><div>// Computed Column</div><div>cs1 = StructureFactory.createComputedColumn();</div><div>cs1.setName("Total Income");</div><div>cs1.setExpression("row["SALARY"]+row["BONUS"]+row["COMM"]");</div><div>computedSet.addItem(cs1);</div><div> </div><div>// get the table header</div><div>RowHandle tableheader = (RowHandle) table.getHeader( ).get( 0 );</div><div> </div><div>// associate the columns in the header row.</div><div>for( int i=0; i < reportCols.length; i++){</div><div>LabelHandle label1 = elementFactory.newLabel( reportCols[1]);</div><div>label1.setStyleName("headerLabel");</div><div>label1.setText(reportCols[1]);</div><div>CellHandle cell = (CellHandle) tableheader.getCells( ).get( i );</div><div>cell.getContent( ).add( label1 );</div><div>}</div><div> </div><div>// HighlightRules</div><div>HighlightRule incomeRule = StructureFactory.createHighlightRule();</div><div>incomeRule.setOperator("le");</div><div>incomeRule.setProperty("backgroundColor","#FF0000");</div><div>incomeRule.setProperty("fontStyle","italic");</div><div> </div><div>incomeRule.setTestExpression("row["Total Income"]");</div><div>incomeRule.setValue1("25000");</div><div> </div><div>// table detail</div><div>RowHandle tabledetail = (RowHandle) table.getDetail( ).get( 0 );</div><div>for( int i=0; i < reportCols.length; i++){</div><div>CellHandle cell = (CellHandle) tabledetail.getCells( ).get( i );</div><div>DataItemHandle data = elementFactory.newDataItem( "data_"+reportCols[0] );</div><div>data.setResultSetColumn(reportCols[0]);</div><div>if(reportCols[0].equalsIgnoreCase("LASTNAME") ||</div><div>reportCols[0].equalsIgnoreCase("Total Income")<span> </span>)</div><div>{</div><div>cell.getPropertyHandle("highlightRules").addItem(incomeRule);</div><div> </div><div>}</div><div>if(reportCols[0].equalsIgnoreCase("HIREDATE"))</div><div>{</div><div>data.setStyleName("dateStyle");</div><div>cell.setStyleName("dateStyle");</div><div>}</div><div> </div><div>cell.getContent( ).add( data );</div><div>}</div><div> </div><div>tabledetail.setStyleName("detailStyle");</div><div> </div><div> </div><div>// format the date element , ie the fourth column.</div><div> </div><div>// Create a label</div><div>LabelHandle label = reportDesignHandle.getElementFactory().newLabel(null);</div><div> </div><div>// Set the properties for the heading</div><div>label.setStringProperty("fontSize", "24pt");</div><div>label.setStringProperty("fontWeight", "bold");</div><div>label.setStringProperty("marginTop", "2pt");</div><div>label.setStringProperty("marginBottom", "5pt");</div><div>label.setStringProperty("textAlign", "center");</div><div>label.setStringProperty("color","blue");</div><div>// The text property</div><div>label.setText("Employee Report 2");</div><div> </div><div>// get the body of the report</div><div>SlotHandle body = reportDesignHandle.getBody();</div><div> </div><div>// add the report caption label to the body of the report</div><div>body.add(label);</div><div> </div><div>// add the table </div><div>reportDesignHandle.getBody( ).add( table );</div><div>reportDesignHandle.saveAs( "E:BITS WSPCEBIRT RESULTSderbysamplede.rptdesign" ); //$NON-NLS-1$</div><div>reportDesignHandle.close( );</div><div> </div><div>}</div><div>catch ( IOException e )</div><div>{</div><div>e.printStackTrace();</div><div>}</div><div>catch ( SemanticException e )</div><div>{</div><div>e.printStackTrace();</div><div>}</div><div>}</div><div> </div><div>/**</div><div>* Build data source. </div><div>* @throws SemanticException</div><div>*/</div><div>public static void addDataSource(ReportDesignHandle hdl,String dsName,String driver,String url,String user, String pwd) </div><div>throws SemanticException</div><div>{</div><div>OdaDataSourceHandle dsHdl = (OdaDataSourceHandle)hdl.findDataSource(dsName);</div><div>if (dsHdl == null )</div><div>{</div><div>dsHdl = hdl.getElementFactory().newOdaDataSource(</div><div>dsName, "org.eclipse.birt.report.data.oda.jdbc" );</div><div>// add the newly created data source</div><div>hdl.getDataSources().add(dsHdl);</div><div>}</div><div> </div><div>// update the properties of the datasource</div><div>dsHdl.setProperty( "odaDriverClass",driver);</div><div>dsHdl.setProperty( "odaURL", url);</div><div>dsHdl.setProperty( "odaUser", user);</div><div>dsHdl.setProperty( "odaPassword", pwd );</div><div> </div><div>}</div><div> </div><div>void print(String msg)</div><div>{</div><div>System.out.println(msg);</div><div>}</div><div> </div><div>/**</div><div>* Build the query ( data set to use in the report).</div><div>*/</div><div>static void buildDataSet(ReportDesignHandle hdl,String dataSetName,String dataSourceName,String qry) </div><div>throws SemanticException</div><div>{</div><div>OdaDataSetHandle dataSetHandle = hdl.getElementFactory().newOdaDataSet( dataSetName,"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );</div><div>dataSetHandle.setDataSource( dataSourceName );</div><div>dataSetHandle.setQueryText( qry );</div><div> </div><div>PropertyHandle computedSet = dataSetHandle.getPropertyHandle( OdaDataSetHandle.COMPUTED_COLUMNS_PROP );</div><div>// Structure of the computed Column.</div><div>ComputedColumn computedCol = StructureFactory.createComputedColumn();//"ComputedColumns");</div><div>computedCol.setName("Total Income");</div><div>computedCol.setExpression("row["SALARY"]+row["BONUS"]+row["COMM"]");</div><div>computedCol.setDataType("decimal");</div><div>computedSet.addItem( computedCol );</div><div> </div><div>hdl.getDataSets( ).add( dataSetHandle );</div><div>}</div><div> </div><div>}</div><div> </div>