jasper reports tutorials


  • WatchHow to create a simple Jasper Report in iReports using sample database
  • WatchSimple steps to create Jasper Reports in iReport using JDBC connections
  • WatchHow to deploy a simple Jasper Report on Jasper server using the sample database
  • WatchSetting Java bean set as datasource in iReport - Follow link in description for sample
  • WatchTutorial to create Drill Down Reports using Jasper Reports.
  • WatchCascading Parameters in Jasper Reports
  • WatchHow to implement conditional query in iReport- Using Sample Database- Sample Included
  • WatchIntroduction to Jasper Reports and JasperSoft
  • WatchA tutorial to create drill down charts in Jasper Reports
  • WatchHow to set JRDatasourceProvider and custom JRDatasource as datasource in iReport along with sample
  • WatchHow to use styles in Jasper Reports
  • WatchTutorial to use Dynamic Parameters in JasperSoft Studio 5.5
  • WatchTutorial to implement Portrait and Landscape orientation in a Single Jasper Report
  • WatchAll about Scriptlet Custimization in Jasper Reports- Along with a working sample
  • WatchHow to enable Mail Subscription in Jasper Server and attach it to the report scheduler
  • WatchGetting to know the features and UI of Jasper Reports Server

making a record with JasperReports

getting ready presentation-nice reports is an standard incidence, so any device that makes the job simpler is price a glance. For developers working with Java, one such is JasperSoft’s JasperReports, which is able to bearing a variety of outputs, including HTML, PDF, Excel XLS, CSV and XML book codecs. The device can build dynamic displays from both changeless records or records retrieved form a database desk the use of an SQL query, and is advised to be integrated directly into JavaJ2EE applications.

This tutorial sets out to exhibit the necessities of how JasperReports will also be used. The device will also be used with a lot of Java IDEs, such as eclipse, and with software servers reminiscent of JBoss. in this example, despite the fact, JDeveloper is used since it contains an anchored application server. The examples created are a PDF report and an Excel record.

Basic bureaucracy

download the initiate supply JasperReports tool jar book jasperreports-1.2.7.jar. you will also should down load the iText Java-PDF library itext-1.4.5.jar, the Jakarta-POI zip book poi-bin-2.5.1-closing-20004.zip, and the aliment Digester 1.7 abstract the zip file to a directory.

again installation the JDeveloper 10g IDE studio version complete installation and oracle database 10g.

actualize an instance database table, archive; from which you’ll accomplish your JasperReports record. create the database table in answer SQL *plus using the SQL calligraphy, archive.sql, which is attainable in the elements zip book, to actualize the illustration table.

create a JDBC affiliation to the answer database from the JDeveloper IDE. To create a connection opt for the access tab, choose the Database node in the connections Navigator, correct click on the Database node, and choose New Database connection. within the actualize Database affiliation wizard specify ethics for the distinctive connection parameters. A affiliation bulge receives introduced to the connections Navigator as shown in figure 1. The JDBC affiliation OracleDBConnection is purchasable as a JNDI resource jdbcOracleDBConnectionDS. This should be used to retrieve facts from the database to accomplish the JasperReports file.

ultimately, for now, you’ll also have to down load and set up adobe Acrobat clairvoyant.

setting up JasperReports

in this part, a JasperReports task is created in JDeveloper IDE and the libraries required for the JasperReports file are delivered to the project.

first, opt for file>New within the JDeveloper IDE. in the New arcade body choose widespread in the categories listed and choose utility within the items listed. Specify an utility name within the create utility body and a challenge name within the create project body. A JasperReports software and assignment get delivered to the applications-Navigator see figure 2.

subsequent, add the libraries required to generate a JasperReports record to the project. opt for the JasperReports undertaking bulge within the applications-Navigator and choose tools>>undertaking houses. in the mission properties body select the Libraries node. Add a library with the Add Library button and add a Jardirectory with the Add Jardirectory button. Add the librariesJar data listed in the following desk.

assignment LibraryJarZip

interpretation
jasperreports-1.2.7.jar

JasperReports API
aliment BeanUtils

JavaBeans utility classes
aliment Collections

Collections framework addendum courses
commons-digester-1.7.jar

classes for processing XML documents.
aliment Logging

Logging classes
poi-bin-2.5.1-final-20004.zip

Jakarta POI API to generate an Excel doc
itext-1.four.5.jar

PDF library
answer XML Parser v2

XML parser API

The libraries created are listed within the Libraries body see determine three. click on the adequate button in the assignment homes frame.

Configuring the JasperReports XML book

The JasperReports document design is specific in a XML agreement book, referred to as archive.xml during this illustration, and here is configured for a PDF record in this part. JasperReports XML configuration files are in accordance with the jasperreport.dtd DTD, with a basis aspect of jasperReport. one of the vital different facets with widely used sub-facets and attributes in a JasperReports XML book are listed in the following table:

XML element

definition

Sub-points

attributes
jasperReport

basis element

reportFont, parameter, queryString, field, capricious, neighborhood, appellation, pageHeader, columnHeader, element, columnFooter, pageFooter.

name, columnCount, pageWidth, pageHeight, orientation, columnWidth, columnSpacing, leftMargin, rightMargin, topMargin, bottomMargin.
reportFont

file level font definitions

name, isDefault, fontName, size, isBold, isItalic, isUnderline, isStrikeThrough, pdfFontName, pdfEncoding, isPdfEmbedded
parameter

article references used in producing a document. Referenced with P$identify

ParameterDescription, defaultValueExpression

identify, class
queryString

Specifies the SQL query for retrieving statistics from a database.


container

Database desk columns included in report. Referenced with F$identify

fieldDescription

name, type
capricious

variable used in the record XML book. Referenced with V$identify

variableExpression, initialValueExpression

identify,classification.
title

file title

band


pageHeader

page header

bandage


columnHeader

Specifies the distinct columns in the report generated.

band


aspect

Specifies the column values

bandage


columnFooter

column footer

band


pageFooter

web page footer

band

A band in a report represents a document part. A band factor contains staticText and textElement features. A staticText aspect is used so as to add static textual content to a record for instance, column headers and a textElement point is acclimated to add dynamically generated text to a report as an example cavalcade values retrieved from a database desk.

In here section headed generating a JasperReports record a JasperReports PDF document and an Excel report are generated from the example catalog table.

The queryString of the instance JasperReports agreement XML book archive.xml specifies the SQL query to retrieve the information for the file:

<queryString><!CDATASELECT CatalogId, Journal,
, Edition, Title,
FROM OE.Catalog> <queryString>

The reportElement features specify the ARIAL_NORMAL, ARIAL_BOLD, and ARIAL_ITALIC fonts used in the file. The PDF record has the columns CatalogId, account, writer, version, title, creator. As normal, the JasperReports agreement file archive.xml is available within the materials zip book.

generating a JasperReports document

The JasperReports classes and interfaces are used to generate a PDFExcel record from the archive.xml file. Add an XML book to the JasperReports task with book>New. in the New arcade frame opt for regular>XML in the categories listed and XML doc in the objects listed. Specify archive.xml because the book identify in the create XML file body. This adds an XML doc to the JasperReports challenge.

reproduction the XML document from the substances zip file to archive.xml. create a listing C:JasperReports and retailer this XML doc in the directory.

Now you actualize a JSP to generate the JasperReports document. select file>New and in the New arcade body select internet bank>JSP within the categories listed and choose JSP in the gadgets listed. within the actualize JSP wizard specify the JSP file ambit. This provides JSP catalog.jsp to the JasperReports undertaking.

The JDBC records source jdbcOracleDBConnectionDS need to then be configured within the JSP internet.xml configuration file. To do that, add the useful resource-ref point below to the net.xml file:

<resource-ref>
<res-ref-name>jdbcOracleDBConnectionDS<res-ref-name>
<res-category>javax.sql.DataSource<res-classification>
<res-auth>container<res-auth>
<useful resource-ref>

in the catalog.jsp, aboriginal import the JasperReports classes and interfaces, as below:

<% page
acceptation,java.io.*,
java.util.*,
java.sqlnnection,
javax.sql.DataSource,
javax.allotment.InitialContext,
web.sf.jasperreports.engine.*,
net.sf.jasperreports.agent.design.JasperDesign,
net.sf.jasperreports.agent.xml.JRXmlLoader,
web.sf.jasperreports.enginensign.*”
%>

next, actualize a InputStream for the JasperReports configuration book archive.xml and load the XML file:

InputStream enter
= new FileInputStreamnew file.”C:JasperReportsarchive.xml”;
JasperDesign architecture = JRXmlLoader.loadinput;

A JasperDesign article represents the record architecture. assemble the report design file to actualize a JasperReport object. The compilation of the record architecture book validates the JasperReports XML book archive.xml with the jaspereports.dtd DTD and converts the document expressions right into a ready-to-consider form:

JasperReport report = JasperCompileManagermpileReportarchitecture;

Now, achieve a JDBC affiliation to retrieve records from the database, to be able to create your PDFExcel file:

InitialContext initialContext = new InitialContext;
DataSource ds = DataSourceinitialContext.look up
“java:compenvjdbcOracleDBConnectionDS”;
affiliation conn = ds.getConnection;

To view this, generate a JasperPrint document, which may well be considered, printed or exported to different formats, from the aggregate document design:

JasperPrint print
= JasperFillManager.fillReportrecord, ambit, conn;

The parameters in the fillReport formulation consist of the constant values distinctive in the constant facets of the XML configuration file. catalog.xml has the parameter ReportTile, so you should specify a value for the ReportTitle parameter:

Map parameters = new HashMap;
ambit.put,ReportTitle”, “PDF JasperReport”;

A JasperReports file could be exported to a XML book, a PDF book, an HTML file, a CSV file, or an Excel XLS file; to consign the JasperReports document we’ve just generated to a PDF book, use this:

OutputStream achievement
= new FileOutputStreamnew book.”C:JasperReportscatalog.pdf”;
JasperExportManager.exportReportToPdfStreambook, achievement;

The instance JSP file, archive.jsp, is attainable in the resources zip file. reproduction the code from elements zip book to catalog.jsp to your JDeveloper mission.

To run the catalog.jsp JSP, correct-click on the catalog.jsp node and select Run see figure four.

This generates a archive.pdf PDF book, which may be opened in an adobe Acrobat clairvoyant as proven in figure 5.

This PDF record archive.pdf is also accessible in the supplies zip file.

If a Excel document is appropriate, conveniently spend the JRXlsExporter object to export your JasperReports document to an Excel spreadsheet, allegorical an acceptable OutputStream. spreadsheet. So, that you can specify a ByteArrayOutputStream for the output from the JRXlsExporter article hence:

OutputStream ouputStream
= new FileOutputStreamnew file,C:JasperReportscatalog.xls”;
ByteArrayOutputStream byteArrayOutputStream
= new ByteArrayOutputStream;

then create a JRXlsExporter object, and set the JasperPrint object from which the report is to be generated and also set the OutputStream, in order to achievement the record:

JRXlsExporter exporterXLS = new JRXlsExporter;
exporterXLS.setParameterJRXlsExporterParameter.JASPER_PRINT,
print;
exporterXLS.setParameterJRXlsExporterParameter.OUTPUT_STREAM,
byteArrayOutputStream;

And, export the JasperReports doc using:

exporterXLS.exportReport;

again output the JasperReports Excel record to an .xls book using:

ouputStream.writebyteArrayOutputStream.toByteArray;
ouputStream.even;
ouputStream.shut;

The archive-excel.jsp JSP within the substances zip book is acclimated to accomplish a Excel spreadsheet corresponding to the PDF file. The Excel spreadsheet may well be opened in MS Excel or Excel viewer as shown in figure 6.

The Excel report archive.xls is available within the elements zip file.

eventually, be aware that however the instance JasperReports record generated in this tutorial is a PDFExcel report, as we’ve already mentioned, it might just as without problems were generated as an HTML, XML, or CSV book.