greenockboy Posted June 9, 2007 Share Posted June 9, 2007 Hi I've created a simple report in ireport that uses an SQL statement as the datasource. The report has been compiled and displayed in ireport. However, I cannot seem to invoke the report from a simple java application and I can't work out why. Here is the code in my very simple app: Code:import net.sf.jasperreports.engine.*;import net.sf.jasperreports.engine.export.*;import java.util.*;public class JasperReportsIntro{ public static void main(String[] args) { JasperReport jasperReport; JasperPrint jasperPrint; try { jasperReport = JasperCompileManager.compileReport( "C:/my_ireports/my_report.jrxml"«»); jasperPrint = JasperFillManager.fillReport( jasperReport, new HashMap(), new JREmptyDataSource()); JasperExportManager.exportReportToPdfFile( jasperPrint, "reports/simple_report.pdf"«»); JasperPrintManager.printPages(myReport, 4, 10, true); } catch (JRException e) { e.printStackTrace(); } }} I have also tried substituting the jrxml file for the jasper file, but still no good. Any help would be greatly appreciated. ThanksGB Link to comment Share on other sites More sharing options...
greenockboy Posted June 12, 2007 Author Share Posted June 12, 2007 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. Code: 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now