save ireport to pdf

Apologies if this isn't the appropriate forum for this topic.

I have created a simple report using ireport and it runs fine within ireport.

However when I attempt to create a pdf file from the .jasper file then I don't appear to get any data. The pdf file is indeed created but it displays only 'null' for both of my fields.

I have trawled through the jasperforge site trying to figure out the cause of the problem but to no avail.

My simple code is shown below:

JasperReport jasperReport;

JasperPrint jasperPrint;

try

{

jasperPrint = JasperFillManager.fillReport("C:/Untitled_report_11.jasper",new HashMap(),new JREmptyDataSource());

JRExporter exporter =new net.sf.jasperreports.engine.export.JRPdfExporter();

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,"Y:/my IReport Stuff/netbean.pdf");

exporter.exportReport();

}

catch (JRException e)

{

e.printStackTrace();

}

I have a feeling that the empty data source is the problem, but not sure why as the compiled .jasper file to the best of my knowledge already has the data.

If anyone can offer any pointers here then they would be very much appreciated.

Regards

GB

Message was edited by:

greenockboy

[1710 byte] By [greenockboya] at [2007-11-27 7:09:22]
# 1

Hi

I have managed to resolve the problem regarding the creation of pdf files containing no data, despite using a pre-compiled .jasper file created in ireports that did indeed contain data.

The problem appears to be related to the using of a JrEmptydataSource object when filling the report. Everywhere I looked I was being told that this was the way to go.

However in order to actually fill my report with data I had to use a Connection object instead.

For those that will experience the same problem as I did then the code that ultimately worked for me is shown below.

JasperReport jasperReport;

JasperPrint jasperPrint;

try

{

Class.forName("ca.edbc.jdbc.EdbcDriver");

Connection conn = DriverManager.getConnection("jdbc:edbc://myDatabase", "myname","myPassword");

jasperPrint = JasperFillManager.fillReport("C:/Untitled_report_11.jasper", new HashMap(), conn);

JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,"C:/example.pdf");

exporter.exportReport();

}

catch (Exception e)

{

e.printStackTrace();

}

Anyway, good luck all and bye for now.

GB

greenockboya at 2007-7-12 19:00:43 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...