user715022
user715022

Reputation: 135

Passing data from main dataset to table dataset

I'm creating simple report in Jaspersoft Studio 5.6.1 with one table.

Sending data to this report from Java via JRBeanCollectionDataSource.

In report I already can get this data vie fields: report-> DAtaset and Query... -> JavaBean Tab -> in Class Name write Java class, that comes in list in JRBeanCollectionDataSource -> add selected fields

So now I can display incoming data.

BUT if I want to do it in Table - I need to create Dataset (why?) and choose 'Use same connection used to fill the master report'. Adding same fields to new dataset doesn't help, neither choosing 'Connect to domain' for dataset. No errors displayed.

enter image description here

Upvotes: 3

Views: 10674

Answers (2)

Ian
Ian

Reputation: 11

i had a similar problem. I find that you just need is set in the table of your report the REPORT_CONNECTION parameter like say

jaspercomunity

in this.

and then left the value in blank. Later in your java code use a maper object for set the SQL connection to your Data Base, something like this:

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=admin");
HashMap<String, Object> hm = new HashMap<String, Object>();
hm.put("REPORT_CONNECTION", conn);
jasperPrint = JasperFillManager.fillReport(reportPath, hm, beanCollectionDataSource);

Upvotes: 1

Darshan Lila
Darshan Lila

Reputation: 5868

I need to create Dataset (why?)

In Jasper Reports tables are loosely coupled to the main report, i.e a table requires its own dataset to deal with.

Now say, you have JRBeanCollectionDataSource ready for the report and you wish to use it to fill table with it. Table as I said requires its own datasert, does also require its own datasource.

Now you can either specify a datasource or use same connection to fill the table as that of main report.

For more on jasper report tables visit this link and on java part visit here.

Upvotes: 2

Related Questions