How to use the same datasource twice in JasperReports/iReport

KCD picture KCD · Sep 28, 2011 · Viewed 8.1k times · Source

I'm trying to work out how best to do reports with a chart then a table representing the same dataset. I need to overcome the positioning of the summary is at the bottom, so intend to use subreports and table-subreports. I am experimenting with two tables and a chart in one detail band.

If I set the datasourceexpression for to $P{REPORT_DATA_SOURCE} only the chart displays data (presumably the first subreport type item) and the tables are empty. Seems the data can be consumed only once?

If I use a Dataset to query the database it works however it executes the Query three times, once for each table/chart. That will be a massive overhead.

Obviously I am not doing this right but I cannot find any examples of using the same dataset more than once.

Answer

KCD picture KCD · Oct 11, 2011

There is no simple answer so I have raised a feature request http://jasperforge.org/projects/jasperreports/tracker/view.php?id=5487

The suggested workarounds were:

  • implement a custom query executer to retrieve data from a cached datasource
  • generate a rewindable datasource based on the retrieved result set

Thanks to sanda aka shertage on the jasperforge forum for these suggestions.