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

Data source for subreport


mackensen

Recommended Posts

Hello,

I have a web application with a main report that is ok. All the data comes from the servlet (including datasource) so there' s no SQL query or database connection in the main report.

In the main report there is one subreport (or even two). How can I connect this subreport to a datasource (the same db connection as for the main report) and use some SQL query the same way as for the main report, I mean without SQL code inside the subreport ? The subreport should receive the id field from the main report as a parameter (for every record of the main report there are some records for the subreport).

Thanx,

mackensen

 

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

i face the same problem as you. i read that JRResultSetDataSource cannot handle this kind of problem.

i also posted my question in this forum but are not getting any replies. i'm looking into using javabean as a custom datasource to pass the data. if you have better suggestion please do share it with the rest of us.

Link to comment
Share on other sites

  • 2 weeks later...

I can now display the main report and subreport, both with datasource supplied from java code but I cannot "connect" the records of main report with those of the subreport, I mean all the records of the subreport come out as soon as the first record of the main record is displayed, instead of having some records of subreport for every record of main report.

So, in the main report and subreport designed with iReport there is no SQL code; the main report has two parameters ("subReport" - type net.sf.jasperreports.engine.JasperReport and "datasource" - type net.sf.jasperreports.engine.data.JRBeanCollectionDataSource).

The main code is:

//for the main report 

parameters_header=generadatipdf.creaMapHeader(request);
dataSource = generadatipdf.createReportDataSource(request, response);
ServletContext context = this.getServletConfig().getServletContext();
File reportFileSubRep = new File(context.getRealPath("/reports/subreport.jasper"));

JasperReport  jasperReportSubRep=null;
jasperReportSubRep = (JasperReport)JRLoader.loadObject(reportFileSubRep.getPath());
 

//for the subreport                                   
dataSourceSubrep=(Collection) generadatipdf.createSubReportDataSource(request, response);     
                                     

//the parameters for the main report

parameters_header.put("subReport", jasperReportSubRep);
parameters_header.put("datasource", new JRBeanCollectionDataSource(dataSourceSubrep));
 

jasperDesign = JRXmlLoader.load(reportFile);

 jasperReport = JasperCompileManager.compileReport(jasperDesign);

...........

 

The problem now is how to "connect" the main report with the subreport. If somebody knows.....

See you,

Mackensen

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