greenockboy Posted June 12, 2007 Share Posted June 12, 2007 Hi I posted a question recently regarding the generation of reports via a java application. My problem is that everytime I try to create a pdf file from my .jasper file then it generates the file but shows no data....only nulls, the report works fine when run from ireport. I have searched the forum on this one and can find no reason for this. Unfortunately I cannot access the zip files containing code examples due to restrictions on my PC. I am sure that it has something to do with the datasource, but alas cannot work out what. Here is my simple code:Code: 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/netbeans.pdf"«»); exporter.exportReport(); } catch (JRException e) { e.printStackTrace(); } If anyone can see any problem in the code I would appreciate some help. Even if the code looks OK at least it will be something. Many 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