Data Source Connection Details Passing from Jasper Server to Sub Report Dynamically

Posted on by By Satya Gopi, in Business Intelligence, Jaspersoft, Open Source Business Intelligence | 0

Data Source Connection Details Passing from Jasper Server to SubReport Dynamically

Make data easy with Helical Insight.
Helical Insight is the world’s best open source business intelligence tool.

Click Here to Free Download

Here is how we get it working using a  MYSQL connection for a subreport which removes the need to hard code the connection to the sub report’s data source on Jaspeserver

Prerequisites:: Ireport 5.6 ,Jasper server 5.6
DataBase : Foodmart,SugarCRM

Step 1 : Create a Main Report with Two Subreports , one subreport pointing to Main Data Source i.e., SugarCRM and for other SubReport foodmart details we need to pass Dynamically

Step 2 : Pass the main data source to the report unit as usual, and create the other data source on jasper server you want to use in the sub report

Step1

Step 3 : In the main report, create a parameter $P{DATA_SOURCE_PATH} where

Parameter Class : com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.JdbcReportDataSource

Default Expression :
com.jaspersoft.jasperserver.api.engine.jasperreports.util.RepositoryUtil.getThreadRepositoryContext().getRepository().getResource(null,”/datasources/FOODMART”)

Step2

In Default Expression we need to pass the DataSource Path which we have created for SubReport

Step 3

Step 4 : Now we can call functions on this parameter and pass in the connection to your subreport as follows

Create a parameter that you will pass to the subreport named SUBREPORT_CONNECTION

Default Expression :

java.sql.DriverManager.getConnection($P{DATA_SOURCE_PATH}.getConnectionUrl(),$P{DATA_SOURCE_PATH}.getUsername(),$P{DATA_SOURCE_PATH}.getPassword())

Step 4

Step 5 : Pass SUBREPORT_CONNECTION parameter to SubReport

Step 5

Step 6 : Deployed in Server and Verify once

Output in Jasper Sever:

Make data easy with Helical Insight.
Helical Insight is the world’s best open source business intelligence tool.

Grab The 30 Days Free Trail

Table using SugarCRM Database
Step 6

Table using FoodMart Database
Step 7

 

logo

Best Open Source Business Intelligence Software Helical Insight is Here

logo

A Business Intelligence Framework

Thanks,
Satya Gopi Parisa,
BI Developer.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments