Jump to content
We've recently updated our Privacy Statement, available here ×

Multiple datasets for a report


chris_42

Recommended Posts

Hi,

I have created several reports, each with a custom JRDataSource. All seems to be well in my Java application. I use JasperFillManager.fillReport(fileName, params, dataSource) followed by JasperExportManager.exportReportToPdf(jasperPrint) and I get the PDF with all the data I want from the JRDataSource.

I now want to create more complicated reports that contain data from multiple (custom) JRDataSources. I cannot see how to add additional JRDataSources in Java to a report. I have read up about subDataSets and subReports but cannot see how I can associate (in Java) different JRDataSources with different subDataSets and/or subReports.

Any guidance you can provide would be most appreciated.

Many Thanks & Regards,

Chris

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi,

Well, I believe I am getting there. In order to get this working in Studio I did the following. It might not all be necessarybut it worked.

1) In Eclipse I created a couple of Adaptors - Java classes (extending JRRewindableDataSource) to provide the data. There must be a constructor with no arguments that sets the java class up properly (e.g. initialising a row counter). This is used in step 7.

2) In Eclipse I created a couple of Providers - Java classes (extending JRDataSourceProvider). Each Provider returned one of the Adaptors. The Providers return the column details (i.e. JRFields) with getFields(JasperReport arg0) and supportsGetFieldsOperation() must return true. This is helpful when adding the Data Adapters to the report in steps 5 and 7.

3) I created a JAR file containing the above 4 Java classes

4) In Studio I created a couple of Data Adapters . Each referenced a Provider Java class from step 2. Each references the JAR file created in Step 3

5) In Studio I created a report. I selected one of the Data Adapters from step 4

6) In the report I added a couple of "Text Fields" into the "Detail 1" band and made sure I got the data from the Data Adapter I had added to the report

7) In the report I added a Table into the "Column Footer" band. I selected the second Data Adapter created in Step 4. I set the Data Adapter to "Use a JRDatasource expression" and set this to the constructor for the Java class specified in the Data Adapter. i.e. new <packagename>.TestDataQueryTwoAdapter()

8) I put the JAR file created in step 3 into the Jasper Project's Build Path.

When executing the report I get the "Test Fields" in the "Detail 1" band populated from one Adapter and the table is populated with the data from the second Adapter.

Currently the 2 Adapters created in step 1 contain dummy data. I will now modify these to connect to the applications they need to and try again. Once that is done I should be able to wrap this up into a java process which users can run on demand  (or on a schedule) to produce the reports they want.

If anyone wants more details on this please let me know.

Thanks & Regards,

Chris

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...