Jump to content

Subreport datasource


pedrogs

Recommended Posts

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

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

  • 5 months later...
  • 2 weeks later...
  • 2 years later...

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

  • 3 years later...

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 report

2. in the main report, create a parameter $P{yourDataSourceParam} with Class type: com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.JdbcReportDataSource

and 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 this

4. 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

  • 4 months later...

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...