public void saveReport() //throws BirtException, IOException, NumberFormatException, PortalException, SystemException { try{ designConfig = new DesignConfig(); designConfig.setBIRTHome(getText("runtime-path")); Platform.startup(designConfig); IDesignEngineFactory designFactory = (IDesignEngineFactory) Platform.createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY); //create an instance of the design engine. IDesignEngine designEngine = designFactory.createDesignEngine(designConfig); SessionHandle session = designEngine.newSessionHandle(ULocale.ENGLISH); //Then, create a new report design. ReportDesignHandle design = session.createDesign(); //Next, get the "element factory" that creates new elements within your design: ElementFactory factory = design.getElementFactory( ); //Next, we add a page master that determines how the report will appear when printed: DesignElementHandle element = factory.newSimpleMasterPage( "Page Master" ); design.getMasterPages( ).add( element ); //This design will contain a grid that contains an image and a label. //Let's first create the datasource and its dataset we need to derive data from db . DataSourceHandle odaDS = factory.newOdaDataSource("ODADataSource","org.eclipse.birt.report.data.oda.jdbc"); odaDS.setStringProperty("odaDriverClass", getText("db-driverClass")); odaDS.setStringProperty("odaURL", getText("db-url")); // we should change it odaDS.setStringProperty("odaUser", getText("db-username")); odaDS.setStringProperty("odaPassword", getText("db-password")); design.getDataSources().add(odaDS); //DataSet OdaDataSetHandle dataSetHandle = factory.newOdaDataSet("Data Set","org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet"); dataSetHandle.setDataSource("ODADataSource"); String queryText = "select "; Set tables = new HashSet(); //we complete queryText later in the next for loop //next we create a table and add it to the report's body slot. REPORTLocalServiceUtil.getREPORT(Long.parseLong(getSelectedReportId())); DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(REPORT_FIELD.class); dynamicQuery.add(PropertyFactoryUtil.forName("BAHMAN_REPORT_FIELD_REPORT_id").eq(Long.parseLong(getSelectedReportId()))); List reportFields = (List)REPORT_FIELDLocalServiceUtil.dynamicQuery(dynamicQuery); TableHandle table = factory.newTableItem(null, reportFields.size(), 1,1,1); design.getBody().add(table); table.setWidth("100%"); table.setDataSet(dataSetHandle); //Next, we should create Labels and Data items and add them to details slot of table. RowHandle tableHeader = (RowHandle) table.getHeader().get(0); RowHandle tableDetail = (RowHandle) table.getDetail().get(0); for( int i=0; i < reportFields.size(); i++) { //add a label to column number i in the header of table REPORT_FIELD field = reportFields.get(i); LabelHandle label = factory.newLabel(field.getBAHMAN_REPORT_FIELD_form_field_name()); label.setText(field.getBAHMAN_REPORT_FIELD_title()); CellHandle cell = (CellHandle) tableHeader.getCells().get(i); cell.getContent().add(label); //add a Data item to column number i in the detail of table DataItemHandle dataitem = factory.newDataItem(field.getBAHMAN_REPORT_FIELD_form_field_name()); dataitem.setResultSetColumn(field.getBAHMAN_REPORT_FIELD_form_field_name()); CellHandle cellOfDetail = (CellHandle) tableDetail.getCells().get(i); cellOfDetail.getContent().add(dataitem); queryText += field.getBAHMAN_REPORT_FIELD_form_field_name(); if(i!=reportFields.size()-1) queryText+=","; tables.add(field.getBAHMAN_REPORT_FIELD_form_name()); } queryText += " from "; Iterator iter = tables.iterator(); while(iter.hasNext()) { queryText += iter.next() + ","; } queryText = (String) queryText.subSequence(0, queryText.length()-1); // removes last , dataSetHandle.setQueryText(queryText); design.getDataSets().add(dataSetHandle); // we should build query text //Finally, save and close the report design. //design.saveAs(getText("save-path") + "/sample.rptdesign"); design.saveAs("D:/Birt/Report/sample.rptdesign"); design.close(); //You can now open the design within BIRT and preview it. }catch(Exception e) { e.printStackTrace(); } }