【问题标题】:Table tool in showing one fewer database records表工具在显示少一个数据库记录
【发布时间】:2014-01-02 00:25:50
【问题描述】:

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

请找到屏幕截图。

还可以找到 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 条。

【问题讨论】:

    标签: database jasper-reports ireport


    【解决方案1】:

    我在使用 JRBeanCollectionDataSource 时会发生这种情况。我知道所有数据都在那里,但表格工具总是丢失第一行。 看起来主报告在集合上执行了“.next()”或其他东西,然后子报告(又名表)继续处理其余数据

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

    所以,总而言之,我在我的 jrxml 文件中做了这个: &lt;dataSourceExpression&gt;&lt;![CDATA[$P{REPORT_DATA_SOURCE}.cloneDataSource()]]&gt;&lt;/dataSourceExpression&gt;

    但只是因为我使用的是JRBeanCollectionDataSource

    【讨论】:

    • cloneDataSource 为我工作:)。谢谢。
    • cloneDataSource 在显示表格中的所有行方面对我有用,但不知何故,表格本身被绘制的次数与行数一样多!!!
    【解决方案2】:

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

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

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

    【讨论】:

    • 您可以直接在您的答案中添加该链接的相关文本/代码块吗?
    【解决方案3】:

    也许你应该使用&lt;connectionExpression&gt;&lt;![CDATA[$P{REPORT_CONNECTION}]]&gt;&lt;/connectionExpression&gt;而不是&lt;dataSourceExpression&gt;&lt;![CDATA[$P{REPORT_DATA_SOURCE}]]&gt;&lt;/dataSourceExpression&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-29
      • 1970-01-01
      • 1970-01-01
      • 2020-10-30
      • 2015-06-13
      • 1970-01-01
      • 1970-01-01
      • 2011-05-11
      相关资源
      最近更新 更多