表工具显示少一个数据库记录

时间:2011-05-18 14:59:36

标签: database jasper-reports ireport

主要关注的是我的查询在SQL中以及在表数据集查询预览中顺利运行。我的意思是在表数据集查询数据预览中,它显示了我数据库表中的2条记录。

请找到屏幕截图enter image description here

还可以找到Jrxml文件。

<?xml version="1.0" encoding="UTF-8"?>
<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="report2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="Table Dataset 1">
        <queryString>
            <![CDATA[select lname, fname from test1
order by fname]]>
        </queryString>
        <field name="lname" class="java.lang.String"/>
        <field name="fname" class="java.lang.String"/>
    </subDataset>
    <subDataset name="New Dataset 1">
        <queryString language="SQL">
            <![CDATA[select lname, fname from test1
order by fname]]>
        </queryString>
        <field name="lname" class="java.lang.String"/>
        <field name="fname" class="java.lang.String"/>
    </subDataset>
    <queryString>
        <![CDATA[select lname, fname from test1
order by fname]]>
    </queryString>
    <field name="lname" class="java.lang.String"/>
    <field name="fname" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="61" splitType="Stretch">
            <staticText>
                <reportElement x="100" y="41" width="102" height="20"/>
                <textElement/>
                <text><![CDATA[lname]]></text>
            </staticText>
            <staticText>
                <reportElement x="202" y="41" width="147" height="20"/>
                <textElement/>
                <text><![CDATA[fname]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <componentElement>
                <reportElement key="table" style="table" x="100" y="0" width="360" height="86"/>
                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="Table Dataset 1">
                        <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="90">
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement/>
                                <textFieldExpression class="java.lang.String"><![CDATA[$F{lname}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement/>
                                <textFieldExpression class="java.lang.String"><![CDATA[$F{fname}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

但pdf报告中的输出只有1条记录,即最后1条。 enter image description here

3 个答案:

答案 0 :(得分:3)

使用JRBeanCollectionDataSource时会发生这种情况。我知道所有数据都存在,但表工具一直缺少第一行。 看起来主报告在集合上执行“.next()”,然后子报表(a.k.a表)继续执行其余数据

无论如何,我解决了它通过 $ P {REPORT_DATA_SOURCE} .cloneDataSource()作为表的dataSource表达式。然后看起来表格以一个全新的数据源开始,并且可以遍历所有项目,因此,它可以工作。 我不知道您使用的数据源是什么,但在使用子报表之前,您必须想办法将光标移动到数据的开头。

所以,总结一下,我在我的jrxml文件中做了这个:     <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}.cloneDataSource()]]></dataSourceExpression>

但仅仅因为我使用的是JRBeanCollectionDataSource

答案 1 :(得分:1)

与kawda完全相同的问题和与user1972796完全相同的行为:多个表而不是一个,但在一个表中的行数正确。

问题接缝出现在主报表未迭代任何内容并且子报表已放入详细信息区并通过$ P {REPORT_DATA_SOURCE}引用主数据源的情况下

解释(和解决方案)接缝就是这个:http://community.jaspersoft.com/wiki/why-first-record-missing-my-subreport

答案 2 :(得分:0)

也许您应该使用<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>代替<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>