Java Reference
In-Depth Information
Clicking on the nodes will direct the main window to the appropriate anchor.
Handling Very Large Reports
Sometimes, when filling a report, the report datasource may have a lot of data. In
some cases, the generated report can become very large, larger than the memory
allocated for the JVM, causing an OutOfMemoryException .
It is possible to set up JasperReports so that it stores segments of a report on disk
in order to free up some memory. This can be accomplished by using the REPORT_
VIRTUALIZER built-in report parameter. The value for this parameter must be an
instance of a class implementing net.sf.jasperreports.engine.JRVirtualizer .
JasperReports comes with an implementation of this interface, namely net.
sf.jasperreports.engine.fill.JRFileVirtualizer . This implementation
is sufficient to handle the vast majority of large reports. If for some reason this
implementation is not sufficient for our needs, we can always create our own
implementation of net.sf.jasperreports.engine.JRVirtualizer . The following
example illustrates typical usage of JRVirtualizer .
package net.ensode.jasperbook;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRParameter;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.fill.JRFileVirtualizer;
public class DbConnectionReportFill
{
Connection connection;
public void generateReport(String reportName)
{
String reportDirectory = "reports";
JRFileVirtualizer fileVirtualizer =
new JRFileVirtualizer(3, "cacheDir");
HashMap parameterMap = new HashMap(); parameterMap.
put(JRParameter.REPORT_VIRTUALIZER, fileVirtualizer);
try
{
Class.forName("com.mysql.jdbc.Driver");
 
Search WWH ::




Custom Search