Download presentation
Presentation is loading. Please wait.
Published byLesley Gray Modified over 9 years ago
1
Generating reports with JasperReports Sean C. Sullivan Portland Java Users Group April 2004
2
Agenda JasperReports JasperAssistant
3
JasperReports http://jasperreports.sourceforge.net/ open source Java reporting tool
4
Using JasperReports 1.Create a JRXML file 2.Load the JRXML file 3.Compile the report 4.Fill the report with data 5.Export the report (PDF, HTML, etc)
5
Hello Jasper import dori.jasper.engine.*; import dori.jasper.engine.design.*; import java.sql.*; JasperDesign design = JasperManager.loadXmlDesign("hello.jrxml"); JasperReport report = JasperManager.compileReport(design);
6
Hello Jasper ResultSet rs = getResultSet(); JRDataSource dataSource = new JRResultSetDataSource(rs); Map params = new java.util.HashMap(); params.put("Bonus", new Integer(12000)); params.put("Year", “2004”);
7
Hello Jasper JasperPrint print = JasperManager.fillReport( report, param, dataSource); JasperExportManager.exportReportToHtmlFile( print, "hello.html"); JasperExportManager.exportReportToPdfFile( print, "hello.pdf"); JasperExportManager.exportReportToXmlFile( print, "hello.xml", false);
8
JasperReports 101 design objects –JasperDesign report objects –JasperReport datasource objects –JRDataSource print objects –JasperPrint
9
XML report templates jasperreport.dtd File extension: jrxml
10
Example: JRXML file
11
JasperDesign objects JasperManager.loadXMLDesign JasperManager.loadDesign
12
Manager classes dori.jasper.engine.JasperManager dori.jasper.engine.JasperCompileManager dori.jasper.engine.JasperFillManager dori.jasper.engine.JasperPrintManager dori.jasper.engine.JasperExportManager
13
Compiling designs JasperDesign design = JasperManager.loadXmlDesign("metrics.jrxml"); JasperReport report = JasperManager.compileReport(design);
14
Ant task: <jrc srcdir="${src.reports.dir}" destdir="${build.dir}/reports" tempdir="${build.dir}/temp" keepjava="true" xmlvalidation="true">
15
Data sources a data source is an object that provides data to Jasper's report engine do not confuse with javax.sql.DataSource
16
JRDataSource interface public interface JRDataSource { public boolean next() throws JRException; public Object getFieldValue(JRField field) throws JRException; }
17
Data source classes JRResultSetDataSource JRBeanArrayDataSource JRBeanCollectionDataSource JRMapArrayDataSource JRMapCollectionDataSource JRTableModelDataSource
18
Output formats CSV (JRCsvExporter) JPEG PDF (JRPdfExporter) XLS (JRXlsExporter) XML (JRXmlExporter) HTML (JRHtmlExporter)
19
JasperReports viewers Swing applications –dori.jasper.view.JasperViewer –dori.jasper.view.JasperDesignViewer
20
JasperViewer
21
JasperAssistant visual report designer commercial tool (not open source) www.jasperassistant.com
22
JasperAssistant JasperAssistant runs inside Eclipse
23
Demo: JasperAssistant
24
Open source projects http://jasperreports.sourceforge.net/ http://www.jfree.org/jfreereport/ http://datavision.sourceforge.net/ http://www.lowagie.com/iText/ http://xml.apache.org/fop/
25
Commercial software ReportMill Actuate Windward Reports Crystal Reports Oracle Reports Cognos ReportNet Hyperion Reports
26
Beyond JasperReports Who is allowed to create and modify report templates? Where are the report templates stored? How will you publish and distribute the reports? Do you need to archive the reports? Will you generate reports on demand or on a fixed schedule (nightly, weekly) ? Is user A allowed to view report B?
27
Conclusion Download JasperReports today http://jasperreports.sourceforge.net
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.