We are exploring Jasper reports to replace our current reporting engine. Our data source will be REST APIs, and we'll be needing to join multiple tables. I came across the CData JDBC driver for REST, and it seemed apt for the purpose.
I have created a JDBC data adapter using the CData driver, with a JSON file as a source which has data for 2 entities - users and posts. Then I created a report with this data adapter to display fields in a table. The data is a result of join query on both the entities as below -
SELECT users.name,users.username,users.email,users.website,posts.title FROM users join posts on users._id = posts.userId
Below is the data adapter configurations -
CDataDataAdapter.xml
<jdbcDataAdapter class="net.sf.jasperreports.data.jdbc.JdbcDataAdapterImpl">
<name>CDataDataAdapter</name>
<driver>cdata.jdbc.rest.RESTDriver</driver>
<username />
<password />
<savePassword>true</savePassword>
<url>jdbc:rest:Format="JSON";URI="D:/Documents/ToJasper/SampleJoinJson.json";XPath="/posts;/users";DataModel="Relational";JSONFormat="JSON";SSLServerCert="*";Logfile="D:\Documents\Tasks\ToJasper\cdata-driver.log";Verbosity="4";Location="D:\Documents\Tasks\ToJasper\Schema";FlattenObjects="False";GenerateSchemaFiles="OnStart";RowScanDepth="10";</url>
<database />
<serverAddress />
<classpath>I:\Program Files\CData\lib\cdata.jdbc.rest.jar</classpath>
<classpath>I:\Program Files\CData\lib\rssbus.jar</classpath>
</jdbcDataAdapter>
The data is fetched the rendered in the report, but the problem is it gets repeated.
The table is repeated in the report 5 times, 4 times with full data, and one time with only column headers. I cannot understand why, any help is greatly appreciated.
I got the answer here - https://community.jaspersoft.com/questions/904196/same-detail-shown-multiple-times-page-and-multiple-pagesireports-well-jaspersoft
I added the table component in the Detail band instead of Summary band. Quoting from the answer above - "Where did you put the table and chart element in the report? They should be placed in SUMMARY section, not detail section. JR report detail band is called for each row fetched into report. If you have 100 rows, it will display information in the detail band 100 times each with details of that row. Tables and charts gather and tally all your data to display and should be placed in the summary band thus have them displayed only once."