显示少一条数据库记录的表格工具

发布于 2024-11-08 12:49:31 字数 5740 浏览 0 评论 0原文

主要关心的是我的查询在 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 条。 在此处输入图像描述

the main concern is my query is running smoothly in SQL and also in table dataset query preview. i mean in table dataset query data preview it's displaying 2 records from my database table.

please find the screen shotenter image description here.

also find Jrxml file.

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

but the output in pdf report is only 1 record which is last 1.
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

若无相欠,怎会相见 2024-11-15 12:49:31

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

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

所以,总结一下,我在 jrxml 文件中执行了此操作:

但只是因为我使用的是 JRBeanCollectionDataSource

This is happening to me when using a JRBeanCollectionDataSource. I know for a fact that all the data is there but the table tool keeps missing the first row.
It looks like the main report executes a ".next()" on the collection or something then the subreport (a.k.a table) keeps on going with the rest of the data

Anyway, I solved it passing $P{REPORT_DATA_SOURCE}.cloneDataSource() as the dataSource expression of the table. Then it looks like the table starts with a brand new datasource and can iterate through all the items, and so, it works.
I don't know what datasource you are using but you have to figure out a way to move the cursor to the beginning of your data before using the subreport.

So, summing up, I did this in my jrxml file:
<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}.cloneDataSource()]]></dataSourceExpression>

but Only because I am using a JRBeanCollectionDataSource

风筝有风,海豚有海 2024-11-15 12:49:31

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

如果主报告不迭代任何内容并且子报告已放入详细信息带并通过 $P{REPORT_DATA_SOURCE} 引用主数据源,则问题似乎会出现

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

Exactly the same problem as kawda and exactly the same behavior than user1972796 : multiple tables instead of one, but correct number of rows in one table.

The problem seams to appear in cases where the master report doesn't iterate over anything and the subreport has been put into the Details Band and references the master data source via $P{REPORT_DATA_SOURCE}

The explanation (and solution) seams to be this one: http://community.jaspersoft.com/wiki/why-first-record-missing-my-subreport

暗喜 2024-11-15 12:49:31

也许您应该使用 而不是

Maybe you should use <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>instead <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文