kolja.ehlersiconplc.com Posted August 14, 2008 Share Posted August 14, 2008 Hello,I think this problem has been discussed in this forum but I still cannot seem to find a solution for it. In my master report I have a JavaBean as datasource. So if I compile it in ireport using the Bean datasource everything works out. In my subreport I want to use a jdbc oracle connection. I read to pass the connection to the subreport using $P{REPORT_CONNECTION}:<subreport isUsingCache="true"> <reportElement x="27" y="46" width="493" height="9" key="subreport-1"/> <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression> <subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "SubBericht.jasper"]]></subreportExpression></subreport>But it is not working and is it not obvious that it wont work? I mean the master reports can only start with one datasource and it is the bean so how can it pass a connection to the subreport if it does not itself have a connection present?Thanks Link to comment Share on other sites More sharing options...
kolja.ehlersiconplc.com Posted August 15, 2008 Author Share Posted August 15, 2008 I keep on reading that JasperReports allow multiple datasources. But I still cannot see how this could be possible. I am using runReportToPdfStream() and it allows only EITHER a connection or a JRDataSource so how can I use Beans in my Master report and a Connection in my Subreport or the other way around? I have looked at the subreport sample and all Master and Subreports in that case use a connection so that is not helping. Link to comment Share on other sites More sharing options...
kolja.ehlersiconplc.com Posted August 15, 2008 Author Share Posted August 15, 2008 Is the right way to do it to create a Connection instance and add it to a Hashmap and pass it to the master report which then passes it further to the subreport?Map<String, Connection> parameters = new HashMap<String, Connection>();parameters.put("DBConnection",getConnection(passwd));JasperRunManager.runReportToPdfStream(reportStream, out, parameters, new JRBeanCollectionDataSource(BeanRecordFactory.generateCollection()));Like this? Link to comment Share on other sites More sharing options...
itchytoes Posted August 15, 2008 Share Posted August 15, 2008 I have done a couple of reports where the main datasource is from Oracle and the subreport needs a dataconnection from MySQL, and I did it by opening the MySQL Connection first and then passing that into the main report as a parameter, then passing that in as my <connectionExpression> to the subreport. Betty Link to comment Share on other sites More sharing options...
meta Posted November 17, 2010 Share Posted November 17, 2010 Hi,is there anybody that solved this topic?I'm in the same trouble. I have the main report that uses a JavaBean datasource and i would like to use a JDBConnection for the subreports. As is specified in iReport manuals, it is possible to use a different datasource for the subreports. But does anybody achieved to pas a jdbconnection to a subreport that has it's main report that uses a bean as a datasource?Is it possible to do it with iReport?thnx, in advance! Link to comment Share on other sites More sharing options...
kolja.ehlersiconplc.com Posted November 17, 2010 Author Share Posted November 17, 2010 If I remeber correctly this was the solution:"Is the right way to do it to create a Connection instance and add it to a Hashmap and pass it to the master report which then passes it further to the subreport?Map<String, Connection> parameters = new HashMap<String, Connection>();parameters.put("DBConnection",getConnection(passwd));JasperRunManager.runReportToPdfStream(reportStream, out, parameters, new JRBeanCollectionDataSource(BeanRecordFactory.generateCollection()));" Link to comment Share on other sites More sharing options...
meta Posted November 17, 2010 Share Posted November 17, 2010 Thnks for Your quick reply!actually, before implementing the code, i would like to make a prototype with iReport. Did You achieve it?Best Regards, Link to comment Share on other sites More sharing options...
meta Posted November 17, 2010 Share Posted November 17, 2010 Hi,i found a soluton for using a different datasource for the subreport. Actually, i'm using iReport 3.7.0 and what i did was adding a parameter at the main report that is used instead of the usual built-in parameter $P{REPORT_CONNECTION}.Lets say that the new parameter is $P{SUBREPORT_CONNECTION}. with class name "java.sql.Connection" and default value expression: "java.sql.DriverManager.getConnection("jdbc:mysql://db","user","pwd")".Then, it is possible to reference this parameter at the subreport connection expression instead of referencing REPORT_CONNECTION. Best, 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