pedrogs Posted May 28, 2008 Share Posted May 28, 2008 Hi all, I have a report that includes a subreport stored in the repository as a JRXML file resource. The problem is that the subreport uses a JDBC data source different than the one used in the parent report. I've been trying to find a way to make this work in JasperServer. Initially I thought that I could simply use any data source defined in the repository, but it seems that this is impossible for subreports (or at least I cannot find any way to do it). I've been researching the forum and this is possible if I manually create the connection in the <subreport> section of the parent report: Code:<subreport isUsingCache="true"> <reportElement x="145" y="140" width="368" height="113" key="subreport-3"/> <connectionExpression><![CDATA[java.sql.DriverManager.getConnection("jdbc:mysql://db", "user", "passwd"«»)]]></connectionExpression> <subreportExpression class="java.lang.String"><![CDATA["repo:/reports/subreports/mysubreport"]]></subreportExpression></subreport> This works, but it's not a very elegant solution, and the connection is not managed by JasperServer, so it probably won't be deleted or returned to a pool after the report is generated, which could lead to performance problems. Is it possible to reference a datasource stored in the JasperServer repository in the <connectionExpression> or <dataSourceExpression> tags for a subreport? Any help would be greatly appreciated. Link to comment Share on other sites More sharing options...
lucianc Posted May 30, 2008 Share Posted May 30, 2008 pedrogs wrote:Is it possible to reference a datasource stored in the JasperServer repository in the <connectionExpression> or <dataSourceExpression> tags for a subreport? There is no built-in support for this in JasperServer. Please log a feature request on this here. Regards,Lucian Link to comment Share on other sites More sharing options...
DocJones Posted November 20, 2008 Share Posted November 20, 2008 HeyasI am looking for that feature as well. Unfortunately, the link provided is no longer valid. So basically: Any news on this?regardsMarc Link to comment Share on other sites More sharing options...
swood Posted December 1, 2008 Share Posted December 1, 2008 There is an enhancement request logged at: jasperforge.org/tracker/index.php This feature is not targeted to be done at this time. ShermanJaspersoft Link to comment Share on other sites More sharing options...
mindlayr Posted June 9, 2011 Share Posted June 9, 2011 Why wouldn't you make it possible to chose a datasource for a subreport? Why would you wait to put something like that in? Link to comment Share on other sites More sharing options...
weedpecker Posted June 17, 2011 Share Posted June 17, 2011 This makes no sense whatsoever. I have a report that catches data from our oracle DB. Now I made a master report that fetches data from an excel file and then passes these parameters to the subreport that runs on oracle. But I can't get it to work, because these are two different datasources. (also: I have tried the solution above, but to no avail) Link to comment Share on other sites More sharing options...
ntatlock Posted April 24, 2015 Share Posted April 24, 2015 I know this is an old question, but since it is the first result on google.. Here is how I got it working using a MS SQL connection for a subreport (and using an Oracle db in main report), which removes the need to hardcode the connection to the sub report's data source on Jaspeserver:1. 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 report2. in the main report, create a parameter $P{yourDataSourceParam} with Class type: com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.JdbcReportDataSourceand default value expression: com.jaspersoft.jasperserver.api.engine.jasperreports.util.RepositoryUtil.getThreadRepositoryContext().getRepository().getResource(null,"/Data_Sources/YourDataSource")3. Now you can call functions on this parameter and pass in the connection to your subreport...like this4. On your main report, select the subreport and remove all the expression entries. Create a parameter that you will pass to the subreport named 'REPORT_CONNECTION', with expression like this: java.sql.DriverManager.getConnection($P{yourDataSourceParam}.getConnectionUrl(),$P{yourDataSourceParam}.getUsername(),$P{yourDataSourceParam}.getPassword())5. :) Link to comment Share on other sites More sharing options...
krishnarhl Posted August 28, 2015 Share Posted August 28, 2015 Thanks @ntatlock Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now