Jump to content
We've recently updated our Privacy Statement, available here ×

Clarification: Multiple datasources in a report


darth_fader

Recommended Posts

You have a parent report with multiple subreports, A, B, C.  The parent report and A, B use the same datasource, C needs to use a different one.  

Simply pass the connection needed by C as a parameter to the parent report, then pass that parameter to the subreport as the connection expression, as follows.

in java, put the connection in a the jasperParameters map: 

            jasperParameters.put("oddBallConnection", connection);

 

in jrxml, add the following to the parent report:

        <import value="java.sql.Connection"/>

        <parameter name="oddBallConnection" class="java.sql.Connection"/>
 
add the following to the subreport reference <subreport> as follows:
 
<connectionExpression><![CDATA[$P{oddBallConnection}]]></connectionExpression>
 
You can use as many datasources/connections in jasper as you need.  I referred to the forums when I tried to solve this, and found various responses to the same question.  Hope this helps.
 
 
Link to comment
Share on other sites

  • 3 weeks later...
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Haven't had that situation come up yet; think a subreport is going to expect it's own query/fields etc. If A and B use the same datasource and query, then maybe subreport B isn't necessary. Maybe with some creative thinking you could get the data in the format you need in one report? Possibly use the summary band, or a table/frame/etc.?
Link to comment
Share on other sites

Unless I am misunderstanding something (very possible!) the scenario isn't so unlikely if you use tables, which seem to act just like a subreport, and want a chart too (but not at the bottom)...

 
But yes my problem is quite different to just A and B subreports. I'm sure there is another method but anyway that is all covered in my post here.
 
 
Thanks for replying, don't mean to hijack your post.
Link to comment
Share on other sites

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