Introduction to Jasper Reports
August 31st, 2010
1 comment
| JasperReports is an open source Java reporting tool that can display the report on your screen, to a printer or it can export into the following formats PDF, HTML, Excel, RTF, ODT, Comma-separated values and XML files and now even in Office 2007 formats(DOCX).It can be used in Java-enabled applications, including Java EE or Web applications, to generate dynamic content. Generally the format of the report design is in XML and Jasperreports has it’s own format called .jrxml. With JasperReports, you can design, deploy or embed our world-class reporting tools in your applications or stand alone reporting environment. |
| Features |
|
| Report Generation |
| As i mentioned earlier, Jasper reports uses a special format for designing and generating the output. This format is called JRXML. This JRXML can be manually written using or it can be generated from any tools which helps us to design the Jasper design like iReport, Dynamicreports and Jasper Assistant. The following image illustrate about the flow of an JRXML file into a report output. |
![]() |
| IDE for Report’s Design |
We have many options for designing the reports. Since this is following an XML based design, we can manually write the JRXML and then we can generate the report or we can use an IDE to design the report. There are many tools available for this, they are,
|
| Structure of an JRXML/Jasper Report |
JasperReports’ reports are defined in XML files, which by convention have an extension of jrxml. A typical jrxml file contains the following elements:
|
| Simple 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="DBReport" 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"/>
<queryString>
<![CDATA[SELECT
tblbm_issuedetails.`issue_number`,
tblbm_issuedetails.`issue_createddate`
FROM
`tblbm_issuedetails` tblbm_issuedetails]]>
</queryString>
<field name="issue_number" class="java.lang.String"/>
<field name="issue_createddate" class="java.sql.Timestamp"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="38" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="200" height="38"/>
<textElement textAlignment="Center">
<font fontName="Tahoma" size="24"/>
</textElement>
<text><![CDATA[My First DB Report]]></text>
</staticText>
</band>
</title>
<columnHeader>
<band height="20" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="20" isRemoveLineWhenBlank="true" backcolor="#D4D0C8"/>
<textElement verticalAlignment="Middle">
<font fontName="Tahoma" isBold="true"/>
</textElement>
<text><![CDATA[Issue Number]]></text>
</staticText>
<staticText>
<reportElement x="100" y="0" width="100" height="20" isRemoveLineWhenBlank="true" backcolor="#D4D0C8"/>
<textElement verticalAlignment="Middle">
<font fontName="Tahoma" isBold="true"/>
</textElement>
<text><![CDATA[Created Date]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="21" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="100" height="20" isRemoveLineWhenBlank="true"/>
<textElement>
<font fontName="Tahoma"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{issue_number}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="20" isRemoveLineWhenBlank="true"/>
<textElement>
<font fontName="Tahoma"/>
</textElement>
<textFieldExpression class="java.sql.Timestamp"><![CDATA[$F{issue_createddate}]]></textFieldExpression>
</textField>
</band>
</detail>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
|
| The Preview of the Above Report Design and Report Preview |
| Report Design |
| Report Preview |














