Java Reference
In-Depth Information
servletOutputStream, new HashMap(), csvDataSource);
catch (Exception e)
// display stack trace in the browser
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
Since the constructor for CSVDataSource takes an instance of
Reader as its only argument, and javax.servlet.ServletContext.
getResourceAsStream() returns a , we take advantage of the class. This class takes an InputStream and converts
it to a Reader . We then pass this Reader to CSVDataSource , and proceed just as
we have in previous examples. This example assumes that the CSV file is saved as
AircraftData.csv .
This chapter has given us a quick run through all the non-database datasources
supported by JasperReports, including how to create our own.
We have created reports that use no external datasources by using an empty
datasource and have also used instances of a class implementing java.util.Map
as a datasource by taking advantage of the
JRMapArrayDataSource class. We learned to use plain Java objects as datasources
by employing the net.sf.jasperreports.engine.JRBeanArrayDataSource
and net.sf.jasperreports.engine.JRBeanCollectionDataSource classes.
Besides, we also saw the use of a Swing TableModel and an XML document
as a datasource by implementing the
JRTableModelDataSource and
JRXmlDataSource classes respectively.
We have covered not only the datasources supported by JasperReports, but also created
custom datasources by creating our own JRDataSource implementation. In addition
to datasources, we also discussed how to pass data in the form of report parameters.
Search WWH ::

Custom Search