Jasper Report - Lesson

Post on 11-Feb-2017

330 views 3 download

transcript

JASPER REPORTS - EXPLAINED

THE LIBRARY Can be downloaded at

http://sourceforge.net/projects/jasperreports/?source=directory

LINKING THE LIBRARIES

CREATING A REPORTS STARTS WITH A TEMPLATE

HELLO.JRXML

LINKING TO WINDOWS FORMS[THE CODE]

CONNECT TO THE DATABASE

THE FORM

THE KOWD

import net.sf.jasperreports.engine.*;

import net.sf.jasperreports.view.*;

import javax.sql.*;

import java.util.HashMap;

ESSENTIAL METHODS

JasperCompileManager.compileReport —

The compileReport method takes the JasperReports XML template and compiles it into byte code format (a JasperReports instance), which you can serialize to disk as a .jasper file. You can reuse the compiled templates to generate reports without compiling them unless you've changed the template source. This is similar to the difference between a .jsp file and its compiled servlet class counterpart.

JasperFillManager.fillReport — The fillReport method takes the compiled report (the JasperReports instance), a few user-defined custom parameters, and a JasperReports datasource (an empty instance—more on that later), and fills the report instance with the parameters and data, if any. In this simple static Hello Report World! example, the method fills in nothing but returns an instance of JasperPrint instead.

The JasperPrint instance is an object representation of the completed report. Now all you have to do is instruct JasperReports to write it to disk in the desired and supported formats.

JasperExportManager.exportReportToHtmlFile — The exportReport method takes the JasperPrint instance and a destination file path and creates an HTML file with the report content. Besides HTML, the JasperReports framework supports exporting to PDF, XML, CSV (comma-separated values), XLS, RTF, and text file formats. You can also create custom file formats for export with the extensible JasperReports API.

JasperExportManager.viewReport — The viewReport method displays the generated report in the built-in JasperReport Viewer. This is an optional but handy display that enables you to quickly see how a report looks without opening the generated files.