MingHong Zheng
MingHong Zheng

Reputation: 185

Why only one row is showing in report?

In MySQL workbench I get 3 rows:

mysql> select * from person;
+-----+------+
| ID  | NAME |
+-----+------+
| A01 | A01  |
| A02 | A02  |
| A03 | A03  |
+-----+------+
3 rows in set (0.00 sec)

but when I use jrxml and show to pdf

I just can get a one row

+-----+------+
| ID  | NAME |
+-----+------+
| A01 | A01  |
+-----+------+

and this's my 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="T0113" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" >
    <queryString>
        <![CDATA[select * from person ]]>
    </queryString>
    <field name="ID" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="NAME" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <group name="ID">
        <groupExpression><![CDATA[$F{ID}]]></groupExpression>
    </group>
    <group name="NAME">
        <groupExpression><![CDATA[$F{NAME}]]></groupExpression>
    </group>
    <title>
        <band height="79" splitType="Stretch">
            <staticText>
                <reportElement x="240" y="0" width="100" height="30" />
                <text><![CDATA[PDFPDF]]></text>
            </staticText>
        </band>
    </title>
    <columnHeader>
        <band height="61" splitType="Stretch">
            <textField>
                <reportElement x="170" y="15" width="100" height="30" />
                <textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="320" y="10" width="100" height="30" />
                <textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>
            </textField>
        </band>
    </columnHeader>
</jasperReport>

So how to fix the problem ?

Upvotes: 0

Views: 4084

Answers (2)

Muhammad Zen
Muhammad Zen

Reputation: 1

just change <![CDATA[$F{ID}]]> and <![CDATA[$F{NAME}]]> in the detail band NOT in columnHeader

Upvotes: 0

Petter Friberg
Petter Friberg

Reputation: 21710

This is because you field's are in the wrong band.

Column Header This section appears at the beginning of each column in the generated document.

Detail This section is repeated for each line of data supplied by the report's data source. The detail section can be made of multiple bands.

Currently you have them in the columnHeader you need to but them in the detail band

<detail>
    <band height="61" splitType="Stretch">
        <textField>
            <reportElement x="170" y="15" width="100" height="30" />
            <textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="320" y="10" width="100" height="30" />
            <textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>
        </textField>
    </band>
</detail>

To learn more about different report sections see Tutorial report section and JRBand API

Upvotes: 3

Related Questions