设置动态值数据集参数/ Mainreport参数-IREPORT的默认值

时间:2011-12-21 10:38:20

标签: jasper-reports ireport

我想在数据集中设置参数值,实际值是在主报表参数字段中设置但不填充数据集参数,因为两者都是同名。即使在默认值选项中也没有显示设置主报表参数我正在使用ireport 4.0.2。你能告诉我如何动态设置数据集中的参数值,我正在通过HashMap。

提前感谢您的帮助。

`

<subDataset name="dataset1">
        <parameter name="ID" class="java.lang.Integer" isForPrompting="false">
            </parameter>
        <queryString>
            <![CDATA[select FIELD_LABEL,MONTHLY,ANNUAL,SUM FROM SALARY_DETAILS WHERE CANDIDATE_ID=$P{ID}]]>
        </queryString>
        <field name="FIELD_LABEL" class="java.lang.String"/>
        <field name="MONTHLY" class="java.lang.Integer"/>
        <field name="ANNUAL" class="java.lang.Integer"/>
        <field name="SUM" class="java.lang.Integer"/>
    </subDataset>
`

<parameter name="CANDIDATE_ID" class="java.lang.Integer"/>
    <queryString>
        <![CDATA[SELECT FIRST_NAME,LAST_NAME,DATE_OF_JOINING ,DESIGNATION,LABEL,SUM
FROM CANDIDATE C
LEFT JOIN PROFILE_INFO PI ON PI.ID = C.PROFILE_ID
LEFT JOIN LEVELS L ON PI.LEVEL_ID = L.ID
LEFT JOIN SALARY_DETAILS SD ON SD.CANDIDATE_ID = C.ID
WHERE C.ID=$P{CANDIDATE_ID} GROUP BY C.ID=$P{CANDIDATE_ID}]]>
    </queryString>
    <field name="FIRST_NAME" class="java.lang.String"/>
    <field name="LAST_NAME" class="java.lang.String"/>
    <field name="DATE_OF_JOINING" class="java.sql.Date"/>
    <field name="DESIGNATION" class="java.lang.String"/>
    <field name="LABEL" class="java.lang.String"/>
    <field name="SUM" class="java.lang.Integer"/>

final String driverClass = "com.mysql.jdbc.Driver";
            final String connectionURL = "jdbc:mysql://localhost:3306/mydb";
            final String userID = "root";
            final String userPassword = "root";
            HashMap<String, Integer> map = new HashMap<String, Integer>();
            map.put("CANDIDATE_ID",1);
            map.put("ID",1);
            Connection con = null;
            Class.forName(driverClass).newInstance();
            con = DriverManager.getConnection(connectionURL, userID,userPassword);
            InputStream input = new FileInputStream(new File(
                    "/home/user/Desktop/OfferLetter.jrxml"));
            JasperDesign design = JRXmlLoader.load(input);
            JasperReport report = JasperCompileManager.compileReport(design);
            JasperPrint print = JasperFillManager.fillReport(report,map, con);

            OutputStream pdfOP = new FileOutputStream(new File(
                    "/home/user/Desktop/OfferLetter.pdf"));

            JasperExportManager.exportReportToPdfStream(print, pdfOP);
            pdfOP.close();
            con.close();

1 个答案:

答案 0 :(得分:0)

我得到了答案,希望能帮到某个人。

我更改了列表数据源配置并映射了数据集的主报表参数。

  Right Click on List(component) -> Edit list(Component) -> Data source -> use connection expression -->Add parameter and map with default value of main report.