views:

33

answers:

1

I want to create a report that has to call multiple fields from different tables. From what I have read online so far, the only way to do this is to have subreports.

Is this true, or is there a way that I am able to run multiple queries to different tables to retrieve data?

A: 

When you need to run multiple queries you have the following options:

  • Use subreports. This is the oldest (supported since JasperReports 1.x) and most powerful method since it allows you to do pretty much anything with the results of your second query. However it is also laborious and when you have more then one or two subreports it quickly becomes unmanageable.

  • Use datasets. These allow you to run a separate query, the resultset can be use in a limited set of components (charts that I know of)

  • Use tables. These are pretty new (introduced in JasperReports 3.7) and allow you to run a separate query to fill a particular table.

My experience is that in most cases you do not need multiple queries. Most cases can be handled by a single well defined SQL query. If you need data from multiple tables you might get away by carefully joining them in a single query.

R. Kettelerij