title: JasperReports MasterReport->Subreport->Subreport
body: <p>Could anyone give a simple example to call a jasper report with subreport inside subreport from a java program. Something like this (<a href="https://stackoverflow.com/questions/9785451/generate-jasper-report-with-subreport-from-java">Generate Jasper report with subreport from java</a>):</p>
  
  <pre><code>JasperReport jasperMasterReport = JasperCompileManager.compileReport(masterReportSource);
  JasperReport jasperSubReport1 = JasperCompileManager.compileReport(subReportSource1);
  JasperReport jasperSubReport2 = JasperCompileManager.compileReport(subReportSource2);
  
  Map&lt;String, Object&gt; parameters2 = new HashMap()&lt;String, Object&gt;;
  parameters2.put("subreportParameter2", jasperSubReport2);
  
  Map&lt;String, Object&gt; parameters1 = new HashMap()&lt;String, Object&gt;;
  parameters1.put("subreportParameter1", JasperFillManager.fillReportToFile(jasperSubReport1, parameters2, connection));
  
  JasperFillManager.fillReportToFile(jasperMasterReport, parameters1, connection);
  </code></pre>
  
  <p>MasterReport.jrxml</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  --&gt;
  &lt;!-- 2017-05-02T10:06:38 --&gt;
  &lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="MasterReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5adfa1b1-651c-478e-a83b-6230d66dc454"&gt;
   &lt;property name="com.jaspersoft.studio.data.sql.tables" value=""/&gt;
   &lt;property name="com.jaspersoft.studio.data.defaultdataadapter" value="OracleJDBC"/&gt;
      &lt;parameter name="subreportParameter1" class="net.sf.jasperreports.engine.JasperReport"/&gt;
   &lt;queryString language="SQL"&gt;
    &lt;![CDATA[SELECT "PERSON"."ID",
   "PERSON"."FIRST_NAME",
   "PERSON"."LAST_NAME"
  FROM "PERSON"]]&gt;
   &lt;/queryString&gt;
   &lt;field name="ID" class="java.math.BigDecimal"/&gt;
   &lt;field name="FIRST_NAME" class="java.lang.String"/&gt;
   &lt;field name="LAST_NAME" class="java.lang.String"/&gt;
   &lt;background&gt;
    &lt;band splitType="Stretch"/&gt;
   &lt;/background&gt;
   &lt;columnHeader&gt;
    &lt;band height="16" splitType="Stretch"&gt;
     &lt;staticText&gt;
      &lt;reportElement x="0" y="0" width="93" height="16" uuid="cde3f82c-d51e-43ef-a56e-fee3cb853b65"/&gt;
      &lt;textElement&gt;
       &lt;font isBold="true"/&gt;
      &lt;/textElement&gt;
      &lt;text&gt;&lt;![CDATA[PERSONS:]]&gt;&lt;/text&gt;
     &lt;/staticText&gt;
    &lt;/band&gt;
   &lt;/columnHeader&gt;
   &lt;detail&gt;
    &lt;band height="80" splitType="Stretch"&gt;
     &lt;textField&gt;
      &lt;reportElement x="0" y="20" width="30" height="20" uuid="9fbab9bb-55ec-44c0-badb-501a00334fe6"/&gt;
      &lt;textFieldExpression&gt;&lt;![CDATA[$F{ID}]]&gt;&lt;/textFieldExpression&gt;
     &lt;/textField&gt;
     &lt;staticText&gt;
      &lt;reportElement x="0" y="0" width="30" height="20" uuid="3c5afed0-442f-41de-9929-abdb8a218981"/&gt;
      &lt;text&gt;&lt;![CDATA[ID]]&gt;&lt;/text&gt;
     &lt;/staticText&gt;
     &lt;textField&gt;
      &lt;reportElement x="30" y="20" width="100" height="20" uuid="2561523d-322d-487d-89a2-be44804979ee"/&gt;
      &lt;textFieldExpression&gt;&lt;![CDATA[$F{FIRST_NAME}]]&gt;&lt;/textFieldExpression&gt;
     &lt;/textField&gt;
     &lt;staticText&gt;
      &lt;reportElement x="30" y="0" width="100" height="20" uuid="431ac382-603e-47a1-b4df-b9d744041718"/&gt;
      &lt;text&gt;&lt;![CDATA[FIRST NAME]]&gt;&lt;/text&gt;
     &lt;/staticText&gt;
     &lt;textField&gt;
      &lt;reportElement x="130" y="20" width="100" height="20" uuid="9b482687-49c6-49f7-b322-ba868e4ce748"/&gt;
      &lt;textFieldExpression&gt;&lt;![CDATA[$F{LAST_NAME}]]&gt;&lt;/textFieldExpression&gt;
     &lt;/textField&gt;
     &lt;staticText&gt;
      &lt;reportElement x="130" y="0" width="100" height="20" uuid="4532e6f3-58c0-4c24-aebc-a135309d94ba"/&gt;
      &lt;text&gt;&lt;![CDATA[LAST NAME]]&gt;&lt;/text&gt;
     &lt;/staticText&gt;
     &lt;subreport&gt;
      &lt;reportElement x="2" y="40" width="550" height="40" uuid="18ecc4c5-81a1-4ae3-b3f7-3bf10c627be8"/&gt;
      &lt;subreportParameter name="PERSON_ID"&gt;
       &lt;subreportParameterExpression&gt;&lt;![CDATA[$F{ID}]]&gt;&lt;/subreportParameterExpression&gt;
      &lt;/subreportParameter&gt;
      &lt;connectionExpression&gt;&lt;![CDATA[$P{REPORT_CONNECTION}]]&gt;&lt;/connectionExpression&gt;
      &lt;subreportExpression&gt;&lt;![CDATA[$P{subreportParameter1}]]&gt;&lt;/subreportExpression&gt;
     &lt;/subreport&gt;
    &lt;/band&gt;
   &lt;/detail&gt;
  &lt;/jasperReport&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Subreport1.jrxml</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  --&gt;
  &lt;!-- 2017-05-02T10:11:02 --&gt;
  &lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Subreport1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a0096e3a-50c2-49db-ba13-71afb020c425"&gt;
   &lt;property name="com.jaspersoft.studio.data.sql.tables" value=""/&gt;
   &lt;property name="com.jaspersoft.studio.data.defaultdataadapter" value="OracleJDBC"/&gt;
   &lt;parameter name="PERSON_ID" class="java.math.BigDecimal"/&gt;
      &lt;parameter name="subreportParameter2" class="net.sf.jasperreports.engine.JasperReport"/&gt;
   &lt;queryString language="SQL"&gt;
    &lt;![CDATA[SELECT "PHONE"."ID",
   "PHONE"."PARENT_ID",
   "PHONE"."PHONE_NUMBER"
  FROM "PHONE"
  WHERE "PHONE"."PARENT_ID" = $P{PERSON_ID} ]]&gt;
   &lt;/queryString&gt;
   &lt;field name="ID" class="java.math.BigDecimal"/&gt;
   &lt;field name="PARENT_ID" class="java.math.BigDecimal"/&gt;
   &lt;field name="PHONE_NUMBER" class="java.lang.String"/&gt;
   &lt;background&gt;
    &lt;band splitType="Stretch"/&gt;
   &lt;/background&gt;
   &lt;columnHeader&gt;
    &lt;band height="20" splitType="Stretch"&gt;
     &lt;staticText&gt;
      &lt;reportElement x="0" y="0" width="100" height="20" uuid="26c75f7b-f80c-41ca-a3fc-eb3317026efd"/&gt;
      &lt;textElement&gt;
       &lt;font isBold="true"/&gt;
      &lt;/textElement&gt;
      &lt;text&gt;&lt;![CDATA[PHONES:]]&gt;&lt;/text&gt;
     &lt;/staticText&gt;
    &lt;/band&gt;
   &lt;/columnHeader&gt;
   &lt;detail&gt;
    &lt;band height="70" splitType="Stretch"&gt;
     &lt;textField&gt;
      &lt;reportElement x="90" y="0" width="454" height="20" uuid="76669766-73b0-47f1-bfff-9337428a4776"/&gt;
      &lt;textFieldExpression&gt;&lt;![CDATA[$F{PHONE_NUMBER}]]&gt;&lt;/textFieldExpression&gt;
     &lt;/textField&gt;
     &lt;staticText&gt;
      &lt;reportElement x="0" y="0" width="90" height="20" uuid="f925e71b-16fe-42ae-8895-143fb886eb63"/&gt;
      &lt;text&gt;&lt;![CDATA[PHONE NUMBER:]]&gt;&lt;/text&gt;
     &lt;/staticText&gt;
     &lt;subreport&gt;
      &lt;reportElement x="0" y="30" width="544" height="40" uuid="029f8258-5205-4e91-ae08-e8d8ec55f5e9"/&gt;
      &lt;subreportParameter name="PHONE_ID"&gt;
       &lt;subreportParameterExpression&gt;&lt;![CDATA[$F{ID}]]&gt;&lt;/subreportParameterExpression&gt;
      &lt;/subreportParameter&gt;
      &lt;connectionExpression&gt;&lt;![CDATA[$P{REPORT_CONNECTION}]]&gt;&lt;/connectionExpression&gt;
      &lt;subreportExpression&gt;&lt;![CDATA[$P{subreportParameter2}]]&gt;&lt;/subreportExpression&gt;
     &lt;/subreport&gt;
    &lt;/band&gt;
   &lt;/detail&gt;
  &lt;/jasperReport&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Subreport2.jrxml</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  --&gt;
  &lt;!-- 2017-05-02T10:13:15 --&gt;
  &lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Subreport2" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9bd68d39-b94b-4e26-94ea-e0dc1e55f226"&gt;
   &lt;property name="com.jaspersoft.studio.data.sql.tables" value=""/&gt;
   &lt;property name="com.jaspersoft.studio.data.defaultdataadapter" value="OracleJDBC"/&gt;
   &lt;parameter name="PHONE_ID" class="java.math.BigDecimal"/&gt;
   &lt;queryString language="SQL"&gt;
    &lt;![CDATA[SELECT "CONTACT_LOG"."ID",
   "CONTACT_LOG"."R_PHONE_ID",
   "CONTACT_LOG"."DSC"
  FROM "CONTACT_LOG"
  WHERE "CONTACT_LOG"."R_PHONE_ID" = $P{PHONE_ID}]]&gt;
   &lt;/queryString&gt;
   &lt;field name="ID" class="java.math.BigDecimal"/&gt;
   &lt;field name="R_PHONE_ID" class="java.math.BigDecimal"/&gt;
   &lt;field name="DSC" class="java.lang.String"/&gt;
   &lt;background&gt;
    &lt;band splitType="Stretch"/&gt;
   &lt;/background&gt;
   &lt;columnHeader&gt;
    &lt;band height="15" splitType="Stretch"&gt;
     &lt;staticText&gt;
      &lt;reportElement x="0" y="0" width="100" height="15" uuid="0779105f-7c86-4541-906f-ea473cdc3ff5"/&gt;
      &lt;textElement&gt;
       &lt;font isBold="true"/&gt;
      &lt;/textElement&gt;
      &lt;text&gt;&lt;![CDATA[CONTACTS:]]&gt;&lt;/text&gt;
     &lt;/staticText&gt;
    &lt;/band&gt;
   &lt;/columnHeader&gt;
   &lt;detail&gt;
    &lt;band height="30" splitType="Stretch"&gt;
     &lt;textField&gt;
      &lt;reportElement x="102" y="0" width="448" height="30" uuid="67919643-f890-4121-ac18-59f87b0752f3"/&gt;
      &lt;textFieldExpression&gt;&lt;![CDATA[$F{DSC}]]&gt;&lt;/textFieldExpression&gt;
     &lt;/textField&gt;
     &lt;staticText&gt;
      &lt;reportElement x="2" y="0" width="100" height="30" uuid="7c3824f0-41ff-4e53-8278-dcd0e535efd4"/&gt;
      &lt;text&gt;&lt;![CDATA[COMMENT:]]&gt;&lt;/text&gt;
     &lt;/staticText&gt;
    &lt;/band&gt;
   &lt;/detail&gt;
  &lt;/jasperReport&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Thanks.</p>