Part I: The detailed process of using ireport to make reports (under Windows environment)

Source: Internet
Author: User
Tags mysql version prepare

Hint: in some plate, the picture in the article does not see, suggest to my blog browsing article: http://blog.csdn.net/jemlee2002/
The article will cover 3 elements:

Part I: The detailed process of using ireport to make reports (under Windows environment)

Part two: Using Jasperreport as a report control to develop FAT client report application

Part III: Using Jasperreport as a report control to develop Web report applications
<?xml:namespace prefix = o ns = "Urn:schemas-microsoft-com:office:office"/>

1. Preface

On the network can search a lot of use ireport and jasperreport work together to achieve a variety of reporting tasks, but I think very few (almost no) to do a more detailed description of how to use ireport to make a report of the whole process, I have read the basic idea of the article is broad coverage , a lot of content is mentioned that, not developers have time for each practice to spend time to achieve their own, if you can have more detailed information, it is not a pleasure. This idea prompted me to write this article, hoping to be helpful to those who use ireport and jasperreport friends, especially those who need to personally implement the report, hoping to bring you a little help. This article is not about each of the details of the ireport, each of the details of ireport can refer to the ireport website, but may cost some money. The general user does not have to pay these fees, because we are concerned about how to make the report we need, rather than to expand ireport, such as the production of ireport Plug-ins.

2. Prepare 2.1. Download JDK

Address: http://www.sun.com, select more than 1.3 version (recommendation 1.4.2 above), install the JDK, the default installation can be; If your system has installed the JDK or has a JRE can omit this step, verify that the JDK or JRE can be run by default, at the command line (CMD) to enter x: >java if appear: Usage:java ... ... the beginning of a heap of information is not only through validation, but in the case of ...... Otherwise, you must configure the configuration information as follows in the Windows environment variable settings:

Path: Add "; Java installation directory" on the last side

Java_home: "Java installation directory"

CLASSPATH: "Java installation directory/bin"
Re-verify that JDK or JRE can be run anywhere in cmd 2.2, download ireport

Address: http://ireport.sourceforge.net/, Select the 0.3.2 version (the version recommended so far) decompression ireport in any directory, after the decompression of the file has a ireport.bat, by double-clicking, over approximately 30 seconds if you can eject the ireport main form that means your system has been able to run the ireport, if you can not eject the main window Body, is generally the first step error, or not completed. 2.3. Prepare the database

ireport supports most databases, as long as the database can provide JDBC drives. This article provides a MySQL database as an example, but the article finally mentions how to configure Oracle support. Please refer to other information regarding the installation and establishment of the database that is outside the scope of this article. This article assumes that MySQL has been installed and that there are already some tables in MySQL, and that there are already data in the table.

* "Special note" MySQL version requirements with the ireport folder in the Lib directory using the MySQL driver compatible, I recommend to http://dev.mysql.com/downloads/download the latest version of the MySQL drive, This will not be a problem for the JDBC drive and should be wary of database support issues. 2.4. Start MySQL service

Determining the character set used by MySQL is an important issue, especially for friends who need a Chinese report. 2.5. Determine business logic

That's what report tasks you want to accomplish. A detailed description of the report that needs to be implemented, which is the business condition for implementing the report, otherwise the majority of all the tasks are meaningless. This article uses a Bug record table, for example, to make a bug count that is grouped according to the modules in the project and the project.
3, start configuration basic information 3.1, configure the interface to use the language and report output path

The first time to enter the system is an English environment, you can use the "Tools"-"options" to open the configuration ireport System Basic Information dialog box. Select the interface language you want in the "Language" option, such as "Chinese-Chinese". Click on the "Apply" button, the system to both the entire interface culture.

In the Configure ireport System Basic Information dialog box, select "Compile" Label, then determine your report output path, you can "compile in the Report Data folder" Selection tick, so that the report jrxml files and Jasper files are placed in the same folder. (You will be asked to save the Jrxml file to the specified folder when you create a new report.)

Some of the parameter modifications in the Options option do not work directly through the Apply button, such as "Look&feel", which must be restarted ireport to work. I don't know if it's a ireport bug. Last "archive". 3.2, the configuration MySQL database connection

This is the interface between the report and the database. The Configure list dialog can be opened through the data source-connection/data source, and ireport will record all previously used connections, unless you manually delete those connections, all of the connections will exist in the connection/Data Source Configuration List dialog box, whether or not they are actually available.

Click "New" to enter the configuration of the new connection interface, as shown in the figure:


Fill in the information required by the JDBC connection, ireport support a variety of data source connections, as shown in the figure:

This article simply introduces the database JDBC connection connection method, which is also the most common way, especially in embedded report applications. After all the information is filled in and tested, the last is to save the information. Go back to the Configure List dialog box, close the dialog box, and complete the MySQL database JDBC connection configuration.
Tip: If you need a report to provide Chinese content, you can do it in the JDBC URL, for example:
jdbc:mysql://localhost/subrdb?user=****&password=****&useunicode=true&characterencoding=gb2312
The * * * number is replaced with the database's user combination password.
3.3, the basic configuration of a new empty report

Click the First tool on the toolbar "new report", create a new statement, enter the name of the report, and define some parameters for the report, such as name Input BUGSRPT (example is the bug Statistics report for a project), click "More ..." to select a label, fill in or select an XML encoding, This is related to your XML support of the selection of character sets, please choose according to need, such as the need for your XML file to support Chinese, then you can enter GB2312 or GBK, then click the "OK" button to enter the report design interface.

* "Special Tips" Please save the report before you start any work, when ireport prompts to save the report location, select the appropriate location, and then enter BUGSRPT as the name. 3.4. Define the type of font and its attributes that the report may need

A report has a variety of contents, a table header, field name, data, other variable information, and so on, if the information is consistent with the font and attributes (such as color), then the entire report is lifeless, it is very rough. We can define the attributes of an element when we add each element to the report, but that's a time-consuming task, and if you can define a combination of attributes in advance, it's easy and quick to select one of these combinations when creating each element.

Click Preview-Report font to open the Custom Combo dialog box. Click "New" to enter the definition Detail dialog box, as shown in the figure: fill in the information and steps in the order in which you define the font combinations in 6 for header, group, column, column, statistics, other, and so on. Note the choice of the PDF inline font, if you need to provide the report in PDF format, then you need to make a choice.


4. Understand several important concepts 4.1, ireport output format

The ireport preview output format can support the following:

PDF, HTML, CSV, java2d, Excel, plain text, Jrviewer, the most common is PDF, jrviewer. This paper takes Jrviewer as an example. Jrviewer is the output format of the report directly in C/S mode, which is output in the JFrame frame. Jasperreport provides the default Jrviewer output class. 4.2, the report of the dynamic object variables, parameters, fields

In the process of using ireport, there are many things related to variables (Variables), Parameters (Parameters), Fields (Fields), and we want to introduce the use and meaning of these objects:

• Field (Fields): database content that is extracted from the database and wants to appear in the report. For example, all values for an ID. $F {Filedsname}

• Parameter (Parameters): This is the entry that your application needs to provide to the report, for example, if you want to provide a condition value for the WHERE statement when the report is interpreted, you can use the parameter (Parameters). $P {parametername}

• Variable (Variables): This is the performance of some logical operations in the report, such as statistical values. $V {Variablesname}

Each object is defined in a format that follows the description of each object, such as defining a variable (Variables), then the expression is written as $v{Variablesname}, and the name of the variable appears in the report. The following article will introduce the use of a detailed method. 4.3, compile, static operation, dynamic operation

Jasperreport runtime needs is a Jasper suffix of the file, the compilation process is actually the jrxml suffix of the file generated Jasper suffix file. (can refer to the operation Principle of Jasperreport)

Static and dynamic running are relative, the latter with the data source running, such as with the database running. The former is static text running, independent of the data source, and NULL if the object associated with the data source appears in the report. 4.4. Report Structure

The structure of a report is roughly a few parts: title, PageHeader, ColumnHeader, Detial, Columnfooter, PageFooter, Summary, GroupHeader, GroupFooter.

· Title: Each report usually has a name, such as XXX Sales report, title is the best place to use the name, of course, you can also be placed in the appropriate place according to need.

PageHeader: Some of the public elements of a report, such as page numbers, creation time, creator, and so on, are the better choices to place here.

ColumnHeader: It's justifiable. Here is the name of the drop column, remember not the column data.

· Detial: Place data that needs to be recycled, such as sales record data.

Columnfooter: The statistics computed value of the drop column level or the description of the column.

pagefooter: Places a page-level statistic or a description of the page.

· Summary: You may need a statistic for several pages (your report may have several pages). For example, 50 sales records take up 3 pages, so the best place to put statistics for these statistics is summary.

GroupHeader: The contents of each table may need to be divided according to a certain attribute to display content and calculation content, such as want to display the sales record separately in each group of months, then you can define a group (the definition of the group reference text), GroupHeader is the best place to place a group description or group logo.

· GroupFooter: The statistics or description of the placement group

5, add objects to the table 5.1. Add static Objects

You can add static objects, such as text, through the toolbar's tools, and click

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.