<div>I use eclipse 4.4.1, windows 8.1, java 7, birt 4.4.1 and the demo-database of birt.</div>
<div> </div>
<div>I have created a report with the Report-Designer with his own DataSource "Classic Models" and his own DataSet "Invoice Data". When i use this report, all went well.</div>
<div>I change the SQL-Statement of the the Dataset in the report on the fly with java-code.</div>
<div>Therefore I wrote the folowing Class "PrintReport". From this class I want to call from outside the method generateReport, to generate 10 Reports from CustomerNumber 100 until 110.</div>
<div>In the demo-database of birt only customernumber = 103 exists. Alle the other customernumbers from 100-110 have no entries.</div>
<div>I want now to chek in the ResultSet of the SQL-Statement, if it is empty or not.</div>
<div>How can i access the ResultSet of the SQL-Statement, to check if it is empty or not and to get the counts of the rows?</div>
<div> </div>
<div>Note: I want all make with java-code.</div>
<div> </div>
<div>
<pre class="_prettyXprint _lang-">
public class PrintReport {
public void generateReports() {
for (int i = 100; i <= 110; i++) {
try {
generateFile(i);
} catch (SemanticException e) {
e.printStackTrace();
} catch (EngineException e) {
e.printStackTrace();
}
}
}
@SuppressWarnings("deprecation")
private void generateFile(int customerNumber) throws EngineException,
SemanticException {
IReportEngine engine = null;
IReportRunnable runnable = null;
EngineConfig config = new EngineConfig();
IPlatformContext context = new PlatformFileContext();
config.setLogConfig("C:/tmp/log/", Level.FINE);
config.setEngineContext(context);
try {
Platform.startup(config);
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.createReportEngine(config);
runnable = engine.openReportDesign("C:/tmp/CustomerOverview.rptdesing");
modifyDataSet(runnable, "Invoice Data", customerNumber);
} catch (BirtException e) {
e.printStackTrace();
engine.destroy();
}
IRunAndRenderTask runAndRenderTask = engine.createRunAndRenderTask(runnable);
ByteArrayOutputStream fso = new ByteArrayOutputStream();
PDFRenderOption options = new PDFRenderOption();
options.setOutputStream(fso);
options.setOutputFileName("C:/tmp/file_CNr-"
+ Integer.toString(customerNumber));
options.setOutputFormat(PDFRenderOption.OUTPUT_FORMAT_PDF);
options.setEmitterID(PDFRenderOption.OUTPUT_EMITTERID_PDF);
options.setSupportedImageFormats("PNG");
runAndRenderTask.setRenderOption(options);
runAndRenderTask.getAppContext().put(
EngineConstants.APPCONTEXT_CLASSLOADER_KEY,
Thread.currentThread().getContextClassLoader());
try {
runAndRenderTask.run();
} catch (EngineException e) {
e.printStackTrace();
}
engine.destroy();
}
public void modifyDataSet(IReportRunnable runnable, String myDataSet,
int customerNumber) {
ReportDesignHandle designHandle = (ReportDesignHandle) runnable
.getDesignHandle();
org.eclipse.birt.report.model.api.ElementFactory designFactory = designHandle
.getElementFactory();
SlotHandle datasets = designHandle.getDataSets();
SlotIterator iter = (SlotIterator) datasets.iterator();
while (iter.hasNext()) {
DesignElementHandle dsHandle = (DesignElementHandle) iter.next();
if (dsHandle instanceof OdaDataSetHandle
&& dsHandle.getName().equals(myDataSet)) {
OdaDataSetHandle datasetHandle = (OdaDataSetHandle) dsHandle;
try {
datasetHandle.clearProperty("queryText");
datasetHandle.setQueryText(queryCustomerNumber(customerNumber));
} catch (BirtException e) {
e.printStackTrace();
}
System.out.println("DataSet: " + dsHandle.getName());
System.out.println("Query Text: "
+ datasetHandle.getQueryText());
} else {
System.out.println("DataSet not used: " + dsHandle.getName());
}
}
}
public String queryCustomerNumber(int CustomerNumber) {
String qry = "";
qry = "SELECT " + "CLASSICMODELS.CUSTOMERS.CUSTOMERNUMBER, "
+ "CLASSICMODELS.CUSTOMERS.CUSTOMERNAME, "
+ "CLASSICMODELS.CUSTOMERS.CONTACTLASTNAME, "
+ "CLASSICMODELS.CUSTOMERS.CONTACTFIRSTNAME, "
+ "CLASSICMODELS.CUSTOMERS.ADDRESSLINE1, "
+ "CLASSICMODELS.CUSTOMERS.ADDRESSLINE2, "
+ "CLASSICMODELS.CUSTOMERS.CITY, "
+ "CLASSICMODELS.CUSTOMERS.POSTALCODE " +
"FROM " + "CLASSICMODELS.CUSTOMERS " +
"WHERE " + "CLASSICMODELS.CUSTOMERS.CUSTOMERNUMBER="
+ Integer.toString(CustomerNumber);
return qry;
}
}
</pre>
</div>
<p> </p>