简体   繁体   English

如何在Jasper Report中打印多行数据

[英]How to print multiple row of data in Jasper Report

Problem : I don't know how to print multiple rows of data from my mySQL database in Jasper Reports. 问题:我不知道如何在Jasper Reports中从mySQL数据库打印多行数据。 I think I should create a loop in the jrxml file but I don't know how. 我想我应该在jrxml文件中创建一个循环,但是我不知道如何。

Basically, I need to print all the data in my database. 基本上,我需要打印数据库中的所有数据。 I would really appreciate any help from you guys, thanks. 非常感谢你们的帮助,谢谢。

Here's the code in the jrxml file : (I removed the top part because it keeps my code from being fully shown here) 这是jrxml文件中的代码:(我删除了顶部,因为它使我的代码无法在此处完整显示)

<queryString language="SQL">
    <![CDATA[select * from employeelist_table]]>
</queryString>
<field name="EMPLOYEE_ID" class="java.lang.Integer"/>
<field name="EMPLOYEE_NAME" class="java.lang.String"/>
<field name="SURNAME" class="java.lang.String"/>
<field name="FIRSTNAME" class="java.lang.String"/>
<field name="MIDDLE_INITIAL" class="java.lang.String"/>
<field name="DEPARTMENT" class="java.lang.String"/>
<field name="POSITION" class="java.lang.String"/>
<field name="GENDER" class="java.lang.String"/>
<field name="BIRTHDATE" class="java.lang.String"/>
<field name="ADDRESS" class="java.lang.String"/>
<field name="CONTACT_NO" class="java.lang.String"/>
<field name="SSS_NO" class="java.lang.String"/>
<field name="BASIC_PAY" class="java.lang.String"/>
<field name="ALLOWANCE" class="java.lang.String"/>
<field name="LEAVE" class="java.lang.String"/>
<field name="NO_WORK" class="java.lang.String"/>
<field name="DAY_RATE" class="java.lang.String"/>
<field name="OVERTIME" class="java.lang.String"/>
<field name="GROSSPAY" class="java.lang.String"/>
<field name="NETPAY" class="java.lang.String"/>
<field name="DAY_ABSENT" class="java.lang.String"/>
<field name="LATE_UNDERTIME" class="java.lang.String"/>
<field name="SSS_PREMIUM" class="java.lang.String"/>
<field name="PHILHEALTH" class="java.lang.String"/>
<field name="WTAX" class="java.lang.String"/>
<field name="RBNI_LOAN" class="java.lang.String"/>
<field name="SSS_LOAN" class="java.lang.String"/>
<field name="TOTAL_DEDUCTION" class="java.lang.String"/>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="79" splitType="Stretch">
        <image>
            <reportElement x="28" y="11" width="255" height="57"/>
            <imageExpression><![CDATA["C:\\Users\\Jaybeeh\\Documents\\Computerized_Payroll_System\\src\\computerized_payroll_system\\logo2.jpg"]]></imageExpression>
        </image>
        <staticText>
            <reportElement x="92" y="20" width="159" height="48"/>
            <textElement/>
            <text><![CDATA[WESTERN COLLEGE, INC.   NAIC, CAVITE                                  PAYROLL SUMMARY]]></text>
        </staticText>
    </band>
</title>
<pageHeader>
    <band splitType="Stretch"/>
</pageHeader>
<columnHeader>
    <band height="31" splitType="Stretch">
        <staticText>
            <reportElement x="33" y="2" width="82" height="20"/>
            <textElement textAlignment="Center"/>
            <text><![CDATA[EMPLOYEE_ID]]></text>
        </staticText>
        <staticText>
            <reportElement x="127" y="2" width="100" height="20"/>
            <textElement textAlignment="Center"/>
            <text><![CDATA[EMPLOYEE_NAME]]></text>
        </staticText>
        <staticText>
            <reportElement x="240" y="2" width="100" height="20"/>
            <textElement textAlignment="Center"/>
            <text><![CDATA[DEPARTMENT]]></text>
        </staticText>
        <staticText>
            <reportElement x="354" y="2" width="68" height="20"/>
            <textElement textAlignment="Center"/>
            <text><![CDATA[BASIC_PAY]]></text>
        </staticText>
        <staticText>
            <reportElement x="432" y="2" width="59" height="20"/>
            <textElement textAlignment="Center"/>
            <text><![CDATA[SSS_LOAN]]></text>
        </staticText>
        <staticText>
            <reportElement x="501" y="2" width="65" height="20"/>
            <textElement textAlignment="Center"/>
            <text><![CDATA[RBNI_LOAN]]></text>
        </staticText>
        <staticText>
            <reportElement x="578" y="2" width="48" height="20"/>
            <textElement textAlignment="Center"/>
            <text><![CDATA[WTAX]]></text>
        </staticText>
        <staticText>
            <reportElement x="639" y="2" width="66" height="20"/>
            <textElement textAlignment="Center"/>
            <text><![CDATA[GROSSPAY]]></text>
        </staticText>
        <staticText>
            <reportElement x="724" y="2" width="63" height="20"/>
            <textElement textAlignment="Center"/>
            <text><![CDATA[NETPAY]]></text>
        </staticText>
    </band>
</columnHeader>
<detail>
    <band height="21" splitType="Stretch">
        <textField>
            <reportElement x="63" y="0" width="29" height="20"/>
            <textElement textAlignment="Center"/>
            <textFieldExpression><![CDATA[$F{EMPLOYEE_ID}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="127" y="0" width="100" height="20"/>
            <textElement textAlignment="Center"/>
            <textFieldExpression><![CDATA[$F{EMPLOYEE_NAME}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="240" y="0" width="100" height="20"/>
            <textElement textAlignment="Center"/>
            <textFieldExpression><![CDATA[$F{DEPARTMENT}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="354" y="0" width="68" height="20"/>
            <textElement textAlignment="Center"/>
            <textFieldExpression><![CDATA[$F{BASIC_PAY}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="432" y="0" width="59" height="20"/>
            <textElement textAlignment="Center"/>
            <textFieldExpression><![CDATA[$F{SSS_LOAN}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="501" y="0" width="65" height="20"/>
            <textElement textAlignment="Center"/>
            <textFieldExpression><![CDATA[$F{RBNI_LOAN}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="578" y="0" width="48" height="20"/>
            <textElement textAlignment="Center"/>
            <textFieldExpression><![CDATA[$F{WTAX}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="639" y="0" width="66" height="20"/>
            <textElement textAlignment="Center"/>
            <textFieldExpression><![CDATA[$F{GROSSPAY}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="724" y="0" width="63" height="20"/>
            <textElement textAlignment="Center"/>
            <textFieldExpression><![CDATA[$F{NETPAY}]]></textFieldExpression>
        </textField>
    </band>
</detail>
<columnFooter>
    <band splitType="Stretch"/>
</columnFooter>
<pageFooter>
    <band splitType="Stretch"/>
</pageFooter>
<summary>
    <band splitType="Stretch"/>
</summary>

Whenever you want to print multiple rows of data in a JasperReport under some fields, put those fields in the Detail band of the report. 每当您想在JasperReport中的某些字段下打印多行数据时,请将这些字段放在报表Detail区域中 The detail band is executed for each row returned in the resultset. 对结果集中返回的每一行执行明细区域。 As such you can print n number of rows in the jasper Report. 这样,您可以在jasper报告中打印n行。 You don't have to put any kind of loop in jrxml or in the jasper report. 您不必在jrxml或jasper报告中放入任何循环。

Detail band is ideally suited for repetitive tasks such as printing multiple rows from database in the report. 详细信息带非常适合重复性任务,例如从报表中的数据库打印多行。

Other way is to group the data and print the data in the Table. 另一种方法是将数据分组并在表中打印数据。 The table uses its own dataset and you can define the query which will return multiple rows and feed the output of this query to the table. 该表使用其自己的数据集,您可以定义查询,该查询将返回多行并将该查询的输出提供给表。

You don't need to write any loop here loop in the jrxml file. 您无需在jrxml文件中在此处编写任何循环。 The detail band is iterative and will automatically loop depending on the number of row returned. 详细信息带是迭代的,并将根据返回的行数自动循环。 I hope you are using the Ireport designer. 我希望您正在使用Ireport设计器。 So make sure that ireport is successfully connected to the database. 因此,请确保ireport已成功连接到数据库。 Which error message is returned whenever you compile or preview your report ? 每当您编译或预览报告时,将返回哪个错误消息?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM