Data Sources and Print Formats

Without a means of supplying content from a dynamic data source, even the most sophisticated and appealing report would be useless. JasperReports allows you to specify fill data for the output report in two ways: parameters and data sources. Both kinds of data are presented by means of a generic interface named JRDataSource, as shown in “Data Source and Parameter Flows for Report Creation”.

Data Source and Parameter Flows for Report Creation

JRDataSource allows a set of records that are organized in tables (rows and columns) to be read. It enables JasperReports to fill a report with data from an explicit data source, using a JDBC connection (already instanced and opened) to whichever relational database you want to run a SQL query on (which is specified in the report).

If the data don't meet your requirements, you may need to specify particular values to condition the report’s execution; you can create name/value pairs to pass to the print engine. These pairs are named parameters, and they have to be preventively declared in the report. Through fillManager, it is possible to join a jasper file and a data source in a JasperPrint object. This object is a meta-print that can create a real print after you have exported it in the desired format through appropriate classes that implement the JRExporter interface.

JasperReports puts at your disposal different pre-defined exporters, such as those for creating files in such formats as pdf, xls, CVS, XML, RTF, ODF, text, HTML and SWF. Through the JRViewer class, you can view the print directly on the screen and print a hardcopy.

Version: 
Feedback