IReport + jasperreport: how to create a sub-table (1)

Source: Internet
Author: User
Subtables are essential in the process of creating a report. I have studied several ways to create a subtable today. I. connect to a database to create a subtable. Take MySQL For example: 1) create a parent table in iReport. This is to create a new table, but remember to select mySQL as the data source. The same applies to other database data sources. 2) After the sub-table is created, we will create the sub-table.

Subtables are essential in the process of creating a report. I have studied several ways to create a subtable today. I. connect to a database to create a subtable. Take MySQL For example: 1) create a parent table in iReport. This is to create a new table, but remember to select mySQL as the data source. The same applies to other database data sources. 2) After the sub-table is created, we will create the sub-table.

Subtables are essential in the process of creating reports. Today I have studied several ways to create subtables.

1. Create a sub-table by connecting to the database

Take MySQL as an example:

1) create a parent table in iReport

This is to create a new table, but remember to select mySQL as the data source. The same applies to other database data sources.

2) After the sub-table is created, we will create a sub-table and drag it to any place in the parent table on the component panel. I put it in detail.

It will generate a wizard

Next, just select use empty datasource In the last item, but select another one. We will modify it later.

3) Let's talk about the principle: This method uses the Parameters attribute that each report has. In iReport4.6, clicking a subreport has two attributes at the bottom of the attribute column on the right.


One is the Parameters attribute, which can be used to pass data to the sub-Table. Next I will talk about it. The second is the Return Values, which obviously can be used to Return the data of the sub-table. This will take some time.

Set the following table attributes:

Note that Subreport Expression is used to specify the path of the sub-Table. After the sub-table is created, it does not need to be modified.

The other is connect type. You need to select the default value when using a datasource express to create a sub-table, that is, the parent connection. This is not the focus currently, but in the subsequent method, this is useful.

The following are the key points:

Set and click Parameters to open such a window. Click add.

This is where your custom Parameters is located. The name can be obtained at will. My settings are as follows: the name is the id field of the database that I want to pass to the sub-Table. At this point, the settings for the master table end.

4) in the following settings, a key point is to create a Parameters in the left-side column of the sub-table, the new name in "right-click" should be the same as the one we created above, and the field type should be the same as the Field passed from the master table: I define the id and the ID field defined in my database is of the String type. Therefore, note that the Default Value Expection must be set to the "" character, otherwise, an error will be reported. It took me several hours.

After setting this, open the small button on the leftmost side of the Data Connection window. After opening it, use the select statement, but use our custom fields, such,

You will find that some attribute fields have been added.

My field and sub-table settings

The following is the preview result.

Source code is sent in the past, hoping to learn together

Go home, continue writing tomorrow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.