Hossam has posted 5 posts at DZone. View Full User Profile

Java Reporting With Jasper Reports - Part 2

06.13.2008
| 211683 views |
  • submit to reddit
Welcome back to Java Reporting series. For those who didn't read the introductory article; have a look here before we get started. Today we're going to have a quick tour in JasperReport architecture, development lifecycle, report definition files, and finally we're going to set up our environment and start work in a sample application.



Architecture

As shown in the above figure JasperReports architecture is based on declarative XML files which by convention have an extension of jrxml that contains the report layout. A lot of third-party design tools were produced to generate your jrxml file in a smooth way (like iReport or JasperAssistant) Design file is supposed to be filled by report's result which is fetched from database, XML files, Java collection, Comma-separated values or Models. Jasper can communicate with those data-sources and more, it can merge any number of data-sources together and manipulates the results of any combinations. This communication goes through JDBC, JNDI, XQuery, EJBQL, Hibernate or existing Oracle PL/SQL. You also can define your own data-source class and pass it to jasper engine directly. After defining your report design layout in jrxml format and determining your data source(s) jasper engine does the rest of work. It compiles your design file and fills it with results fetched from data-source and generates your report to the chosen exporting format (PDF, Excel, HTML, XML, RTF, TXT …, etc.)

Report Definition file structure (jrxml):

Jasper design file –jrxml- contains the following elements:
  • <jasperReport>: the root element.
  • <title>: its contents are printed only once at the beginning of the report
  • <pageHeader> - its contents are printed at the beginning of every page in the report.
  • <detail> - contains the body of the report, repeated by n number of results
  • <pageFooter> - its contents are printed at the bottom of every page in the report.
  • <band> - defines a report section, all of the above elements contain a band element as its only child element.

Only the root element is mandatory, the rest of elements are optional.

 

Environment

To set up working environment we need to download JasperReport jar file from the following URL: http://sourceforge.net/project/showfiles.php?group_id=36382&package_id=28579
And add the following jars to your project classpath:
  • jasperreports-2.0.4.jar
  • commons-digester-1.7.jar
  • commons-collections-2.1.jar (commons-collections.jar)
  • commons-logging-1.0.2.jar
  • commons-beanutils.jar
  • iText-2.0.7.jar (used infor PDF exporting)

Sample application

At this section we'll introduce a sample application that generates PDF, HTML and Excel files contain the results of our report which is built over Oracle database contains the following table:
ITEM

ITEM_ID ---- NUMBER(5) --- NOT NULL
CATEOGRY_ID ---- NUMBER(5) --- NOT NULL
ITEM_NAME ---- VARCHAR2(50) --- NOT NULL
ITEM_DESCIPTION ---- VARCHAR2(200)

ITEM_AMOUNT ---- NUMBER(5) ---- NOT NULL

Result: Report should retrieve the items with amount less than or equal 100 item.

We're going to divide the work into two steps:

  1. Generate the report design (jrxml file).
  2. Implement application that assigns data source, compiles jrxml file and exports result in the chosen format.


Designing The Report

First we create new text file and rename it to sample_report.jrxml, this file should contain the following XML tags.

<!DOCTYPE jasperReport PUBLIC
"//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport name="sample_report" >
<queryString>
<![CDATA[select item_name,item_amount from item
where item_amount <=100]]>
</queryString>
<field name="ITEM_NAME" class="java.lang.String"/>
<field name="ITEM_AMOUNT" class="java.math.BigDecimal"/>
<columnHeader>
<band height="28" isSplitAllowed="true">
<staticText>
<reportElement x="40" y="11" width="193" height="15" key="staticText-1"/>
<text>
<![CDATA[Item Name]]>
</text>
</staticText>
<staticText>
<reportElement x="330" y="11" width="193" height="15" key="staticText-2"/>
<text>
<![CDATA[Item Amount]]>
</text>
</staticText>
</band>
</columnHeader>

<detail>
<band height="27" isSplitAllowed="true">
<textField>
<reportElement x="47" y="6" width="173"
height="18" key="textField"/>
<textFieldExpression class="java.lang.String">
<![CDATA[$F{ITEM_NAME}]]>
</textFieldExpression>
</textField>
<textField >
<reportElement x="330" y="6" width="100"
height="18" key="textField"/>
<textFieldExpression class="java.math.BigDecimal">
<![CDATA[$F{ITEM_AMOUNT}]]>
</textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>

The above XML file consists of the following main sections that defining report behavior and layout:

  • <queryString>: contains the SQL statement which retrieves the report result.
  • <field name>: defines the resulted fields from the query, and give them name to reuse them into the report body [they are case-sensitive].
  • <staticText>: contains the header titles "Item Name" in <![CDATA[Item Name]]> tag format.
  • <textFieldExpression>: defines the appearance of result field.
  • $F{ITEM_NAME}: is a variable contains the value of Query result predefined field in the tag <field name>.

Once we finished the report design file, save it in C:\ directory.

Implementing The Report Service:

- Create a new java project.
- Import the jars listed in environment section to your project libraries.
- Create new class and import the following packages

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.export.JRXlsExporter;


- Define the data source, in my case it's an oracle connection and established by JDBC as following:

public static Connection establishConnection()
{
Connection connection = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
String oracleURL = "jdbc:oracle:thin:@localhost:1521:mySID";
connection = DriverManager.getConnection(oracleURL,"username","password");
connection.setAutoCommit(false);
}
catch(SQLException exception)
{
exception.printStackTrace();
}
return connection;

}

Finally, the core code for compiling, filling and exporting the results in the following sequence:

- Define jasper objects that will hold report template, compiled files, and result files.

/* JasperReport is the object
that holds our compiled jrxml file */
JasperReport jasperReport;


/* JasperPrint is the object contains
report after result filling process */
JasperPrint jasperPrint;

- Create a connection to my data-source; initialize the report parameter into empty HashMap then compile our jrxml file into JasperReport object and finally fill the JasperPrint object by data from data-source connection.

// connection is the data source we used to fetch the data from
Connection connection = establishConnection(); 
// jasperParameter is a Hashmap contains the parameters
// passed from application to the jrxml layout
HashMap jasperParameter = new HashMap();

// jrxml compiling process
jasperReport = JasperCompileManager.compileReport
("C://sample_report.jrxml");

// filling report with data from data source

jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter, connection); 

- Last segment of code is responsible for exporting the result files into different formats

// exporting process
// 1- export to PDF
JasperExportManager.exportReportToPdfFile(jasperPrint, "C://sample_report.pdf");

// 2- export to HTML
JasperExportManager.exportReportToHtmlFile(jasperPrint, "C://sample_report.html" ); 

// 3- export to Excel sheet
JRXlsExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "C://simple_report.xls" );

exporter.exportReport();

You have just managed to generate your first jasper report in 3 different file formats at C:\\ directory (shown in the image below):

- sample_report.html
- sample_report.pdf
- sample_report.xls


 

Here we reach the end of today's article, next article we will cover the following points:
1- Using design tool (iReport) to generate robust and smooth jrxml file.
2- Create run-time search criteria and pass them to report.

Note: this Article was first published in FCI-H Blog, here

Published at DZone with permission of its author, Hossam Sadik.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

labidi chichi replied on Sun, 2008/08/24 - 5:27am

hello,

t the begining i was too happy by finding this tutorial, but after trying it , it doesn't work, there are 51 errors that talk about "symbols not found" , do you know the cause of these problems(i will send you the stack trace if you want), in fact i used commons-logging-1.1.jar instead of commons-logging-1.0.2.jar  and  itext-1.3.1.jar instead of iText-2.0.7.jar

i need your help,

thank you 

 

 

 

Hossam Sadik replied on Sun, 2008/08/24 - 7:03am

@ chflb

 I guess you didn't read the rest of articles, there were two more articles that cover working with designing tools to facilitate report design and remove the overhead of XML work.

you can find those articles at the following URL's:

http://java.dzone.com/articles/java-reporting-%E2%80%93-part-3

http://java.dzone.com/articles/java-reporting-%E2%80%93-part-4

try to figure them out, if you still facing problems don't hesitate to contact me directly.

 

labidi chichi replied on Sun, 2008/08/24 - 10:45am in response to: Hossam Sadik

hello hossam, thank you for your reply,

in fact,i have the jrxml file created, 'd like to say also that i use jsf+jpa

this is my code(the procedure responsable for compiling and exporting pdf) :

  public String generate() 
{
try{
Connection connection = establishConnection();
HashMap jasperParameter = new HashMap();
JasperReport jasperReport = JasperCompileManager.compileReport ("E://rapport/rpt.jrxml");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter, connection);
JasperExportManager.exportReportToPdfFile(jasperPrint, "E://rapport/sample_report.pdf");

}catch(ClassNotFoundException ex)
{ex.printStackTrace();}
catch(JRException jr){jr.printStackTrace();}

return "generate";
   }

 

there are in result 51 errors,(perhaps they will be stupid errors) ;

Initialisation de l'implémentation de JavaServer Faces de Sun (1.2_04-b20-p03) pour le contexte '/rapport'
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:4: package net.sf.jasperreports.engine does not exist
import net.sf.jasperreports.engine.*;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:5: package net.sf.jasperreports.engine.fill does not exist
import net.sf.jasperreports.engine.fill.*;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:18: cannot find symbol
symbol: class JREvaluator
public class report1_1219591204559_305719 extends JREvaluator
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:25: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
private JRFillParameter parameter_REPORT_RESOURCE_BUNDLE = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:26: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
private JRFillParameter parameter_REPORT_CLASS_LOADER = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:27: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
private JRFillParameter parameter_REPORT_FORMAT_FACTORY = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:28: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
private JRFillParameter parameter_REPORT_TIME_ZONE = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:29: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
private JRFillParameter parameter_REPORT_DATA_SOURCE = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:30: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
private JRFillParameter parameter_REPORT_LOCALE = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:31: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
private JRFillParameter parameter_REPORT_URL_HANDLER_FACTORY = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:32: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
private JRFillParameter parameter_REPORT_PARAMETERS_MAP = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:33: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
private JRFillParameter parameter_REPORT_CONNECTION = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:34: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
private JRFillParameter parameter_IS_IGNORE_PAGINATION = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:35: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
private JRFillParameter parameter_REPORT_TEMPLATES = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:36: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
private JRFillParameter parameter_REPORT_VIRTUALIZER = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:37: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
private JRFillParameter parameter_REPORT_SCRIPTLET = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:38: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
private JRFillParameter parameter_REPORT_MAX_COUNT = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:39: cannot find symbol
symbol : class JRFillField
location: class report1_1219591204559_305719
private JRFillField field_TOT_C = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:40: cannot find symbol
symbol : class JRFillField
location: class report1_1219591204559_305719
private JRFillField field_SOLDE_AUTO = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:41: cannot find symbol
symbol : class JRFillField
location: class report1_1219591204559_305719
private JRFillField field_CODE_INFO = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:42: cannot find symbol
symbol : class JRFillField
location: class report1_1219591204559_305719
private JRFillField field_TOT_D = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:43: cannot find symbol
symbol : class JRFillField
location: class report1_1219591204559_305719
private JRFillField field_DERNIER_NPCH = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:44: cannot find symbol
symbol : class JRFillVariable
location: class report1_1219591204559_305719
private JRFillVariable variable_PAGE_NUMBER = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:45: cannot find symbol
symbol : class JRFillVariable
location: class report1_1219591204559_305719
private JRFillVariable variable_COLUMN_NUMBER = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:46: cannot find symbol
symbol : class JRFillVariable
location: class report1_1219591204559_305719
private JRFillVariable variable_REPORT_COUNT = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:47: cannot find symbol
symbol : class JRFillVariable
location: class report1_1219591204559_305719
private JRFillVariable variable_PAGE_COUNT = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:48: cannot find symbol
symbol : class JRFillVariable
location: class report1_1219591204559_305719
private JRFillVariable variable_COLUMN_COUNT = null;
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:71: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
parameter_REPORT_RESOURCE_BUNDLE = (JRFillParameter)pm.get("REPORT_RESOURCE_BUNDLE");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:72: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
parameter_REPORT_CLASS_LOADER = (JRFillParameter)pm.get("REPORT_CLASS_LOADER");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:73: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
parameter_REPORT_FORMAT_FACTORY = (JRFillParameter)pm.get("REPORT_FORMAT_FACTORY");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:74: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
parameter_REPORT_TIME_ZONE = (JRFillParameter)pm.get("REPORT_TIME_ZONE");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:75: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
parameter_REPORT_DATA_SOURCE = (JRFillParameter)pm.get("REPORT_DATA_SOURCE");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:76: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
parameter_REPORT_LOCALE = (JRFillParameter)pm.get("REPORT_LOCALE");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:77: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
parameter_REPORT_URL_HANDLER_FACTORY = (JRFillParameter)pm.get("REPORT_URL_HANDLER_FACTORY");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:78: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
parameter_REPORT_PARAMETERS_MAP = (JRFillParameter)pm.get("REPORT_PARAMETERS_MAP");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:79: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
parameter_REPORT_CONNECTION = (JRFillParameter)pm.get("REPORT_CONNECTION");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:80: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
parameter_IS_IGNORE_PAGINATION = (JRFillParameter)pm.get("IS_IGNORE_PAGINATION");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:81: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
parameter_REPORT_TEMPLATES = (JRFillParameter)pm.get("REPORT_TEMPLATES");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:82: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
parameter_REPORT_VIRTUALIZER = (JRFillParameter)pm.get("REPORT_VIRTUALIZER");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:83: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
parameter_REPORT_SCRIPTLET = (JRFillParameter)pm.get("REPORT_SCRIPTLET");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:84: cannot find symbol
symbol : class JRFillParameter
location: class report1_1219591204559_305719
parameter_REPORT_MAX_COUNT = (JRFillParameter)pm.get("REPORT_MAX_COUNT");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:93: cannot find symbol
symbol : class JRFillField
location: class report1_1219591204559_305719
field_TOT_C = (JRFillField)fm.get("TOT_C");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:94: cannot find symbol
symbol : class JRFillField
location: class report1_1219591204559_305719
field_SOLDE_AUTO = (JRFillField)fm.get("SOLDE_AUTO");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:95: cannot find symbol
symbol : class JRFillField
location: class report1_1219591204559_305719
field_CODE_INFO = (JRFillField)fm.get("CODE_INFO");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:96: cannot find symbol
symbol : class JRFillField
location: class report1_1219591204559_305719
field_TOT_D = (JRFillField)fm.get("TOT_D");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:97: cannot find symbol
symbol : class JRFillField
location: class report1_1219591204559_305719
field_DERNIER_NPCH = (JRFillField)fm.get("DERNIER_NPCH");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:106: cannot find symbol
symbol : class JRFillVariable
location: class report1_1219591204559_305719
variable_PAGE_NUMBER = (JRFillVariable)vm.get("PAGE_NUMBER");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:107: cannot find symbol
symbol : class JRFillVariable
location: class report1_1219591204559_305719
variable_COLUMN_NUMBER = (JRFillVariable)vm.get("COLUMN_NUMBER");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:108: cannot find symbol
symbol : class JRFillVariable
location: class report1_1219591204559_305719
variable_REPORT_COUNT = (JRFillVariable)vm.get("REPORT_COUNT");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:109: cannot find symbol
symbol : class JRFillVariable
location: class report1_1219591204559_305719
variable_PAGE_COUNT = (JRFillVariable)vm.get("PAGE_COUNT");
^
C:\Users\chifa\.personalDomain\personalDomain\config\report1_1219591204559_305719.java:110: cannot find symbol
symbol : class JRFillVariable
location: class report1_1219591204559_305719
variable_COLUMN_COUNT = (JRFillVariable)vm.get("COLUMN_COUNT");
^
51 errors
at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:193)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:220)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:153)
at newpackage.Report.generate(Report.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.el.parser.AstValue.invoke(AstValue.java:187)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
at javax.faces.component.UICommand.broadcast(UICommand.java:383)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:447)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.
apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
localhost:1521:xe
;_RequestID=9f3c7020-39f3-4f81-aac7-bb04d0479e30;|RAR5038 : Exception inattendue lors de la création de la ressource pour le pool oracle-thinPool. Exception : La connexion n'a pu être attribuée pour la raison suivante : Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
localhost:1521:xe
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
localhost:1521:xe
;_RequestID=9f3c7020-39f3-4f81-aac7-bb04d0479e30;|RAR5058 : Erreur lors du redimensionnement du pool oracle-thinPool. Exception : La connexion n'a pu être attribuée pour la raison suivante : Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
localhost:1521:xe
 
i m sorry it's a very long stack,i hope you will help me, thank you again,

 

labidi chichi replied on Sun, 2008/08/24 - 4:36pm in response to: labidi chichi

hello houssem,

i found the solution,in fact there is another jar to be imported, the jar is: jdt-compiler-X.jar,

thank you very much about these series,i hope next time you make a tutorial about how to use JasperServer, because i need now to put the generated pdfs in server to be consulted by the administrator,

 any way, I thank you so much,

+@ 

gagan deep replied on Thu, 2009/02/05 - 7:54am

Hello Sir

I have created the jasper report using xml as shown in the above examplebut now i want to implement pagination in this report.how can i implement it.pls do reply .

 

thx

ali askari replied on Tue, 2009/05/12 - 1:55am

a

ali askari replied on Tue, 2009/05/12 - 1:58am in response to: labidi chichi

hello. String appPath = srvlt.getServletContext().getRealPath("/") ; JRProperties.setProperty(JRProperties.COMPILER_CLASSPATH, JRProperties.getProperty(JRProperties.COMPILER_CLASSPATH) + ";"+ appPath + "WEB-INF/lib/jasperreports-x.jar;"); JasperReport jasperReport = JasperCompileManager.compileReport ("E://rapport/rpt.jrxml"); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter, connection); JasperExportManager.exportReportToPdfFile(jasperPrint, "E://rapport/sample_report.pdf");

Hanen Mbarki replied on Tue, 2010/04/20 - 6:22am

Hello

I'm trying to develpper an application using netbeans and ireport

I use this tutorial to generate pdf file,but I have an

error : Language "null" is not supported by report compiler the .jrxml is correct and it generate a pdf if I use it only 

 

Tamal Nayek replied on Sat, 2010/04/24 - 7:16am

Hi...

 I use this code to generate Excel Report ....

 //My written Code............

       JasperReport jasperReport;
        JasperPrint jasperPrint;


  try{
        Connection con= (Connection)dbcon.getdbConnection();
       HashMap jasperParameter = new HashMap();
jasperReport = JasperCompileManager.compileReport("report/daily_stock_report.jrxml");

jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter, con);

JRXlsExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "E:/simple_report.xls" );
exporter.exportReport();

       }
       catch(Exception e)
       {
           e.printStackTrace();
       }

*********************************************************************************

But I found some ERROR..... 

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFCell.setEncoding(S)V
        at net.sf.jasperreports.engine.export.JRXlsExporter.initCreateCell(JRXlsExporter.java:444)
        at net.sf.jasperreports.engine.export.JRXlsExporter.createTextCell(JRXlsExporter.java:419)
        at net.sf.jasperreports.engine.export.JRXlsExporter.exportText(JRXlsExporter.java:324)
        at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportPage(JRXlsAbstractExporter.java:426)
        at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReportToStream(JRXlsAbstractExporter.java:345)
        at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReport(JRXlsAbstractExporter.java:197)

***************************************************************************************

 Although I added all JAR Files......

    1) iText-2.1.0.jar
    2) jasperreports-3.5.1.jar
    3) jfreechart-1.0.12.jar
    4) commons-collections-2.1.1.jar
    5) displaytag-1.2.jar
    6) jakarta-oro.jar
    7) jxl-2.6.jar
    8) poi-3.2-FINAL.jar
    9) commons-fileupload-1.0.jar

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

PLZ Help some one to execute the error less code...My Total Development is stopped with out generate

Excel Formate Report....... I am eagerly waiting forsome valuable reply....

*********************************************************************************

 

Ananda Jermin replied on Tue, 2010/07/27 - 4:08am

Java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester

Can anyone please Help me with this error. It has made me not use my jasperreport in my program.

the code i use to generate the report is:

 

HashMap map = new HashMap();

Connection con = new connect().odbcConnect();

String reportFile = "E://Projects//NetBeansProjects//kusda//src//kusda//members.jrxml";

try {

       JasperDesign jasperDesign = JRXmlLoader.load(reportFile);

       JasperReport report = JasperCompileManager.compileReport(jasperDesign);

       JasperPrint print = JasperFillManager.fillReport(report, map, con);

       JasperViewer.viewReport(print);

     } catch (Exception ex) {

            ex.printStackTrace();

     }

 

from my tracing i get the source of the error is this line:

JasperDesign jasperDesign = JRXmlLoader.load(reportFile);

Can anyone debug this please? Thank u in advance.

Suresh Murthy replied on Tue, 2011/09/13 - 8:17am

Hi Hossam, Is there a way I can embed the jasper report into an iframe? I tried out the sample code suggested here: http://edwin.baculsoft.com/2010/11/creating-web-based-reports-using-jasper-report/ I am using jsp+servlet in my web application to try this out. All of that is working as expected. But I would like to render the report inside an iframe. Any help in this regard is highly appreciated.

Joguy Djou replied on Wed, 2011/10/12 - 2:48am

helo! Im trying to compile my my report on jrxml file source and getting this :


Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/springframework/core/io/Resource
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java:161)
        at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:119)
        at net.sf.jasperreports.engine.util.ClassUtils.instantiateClass(ClassUtils.java:57)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.instantiateRegistry(DefaultExtensionsRegistry.java:202)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRegistries(DefaultExtensionsRegistry.java:179)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.loadRegistries(DefaultExtensionsRegistry.java:139)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getRegistries(DefaultExtensionsRegistry.java:125)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:102)
        at net.sf.jasperreports.engine.component.ComponentsEnvironment.findComponentBundles(ComponentsEnvironment.java:94)
        at net.sf.jasperreports.engine.component.ComponentsEnvironment.getCachedComponentBundles(ComponentsEnvironment.java:82)
        at net.sf.jasperreports.engine.component.ComponentsEnvironment.getComponentBundles(ComponentsEnvironment.java:70)
        at net.sf.jasperreports.engine.xml.JRReportSaxParserFactory.getSchemaLocations(JRReportSaxParserFactory.java:162)
        at net.sf.jasperreports.engine.xml.JRReportSaxParserFactory.configureParser(JRReportSaxParserFactory.java:143)
        at net.sf.jasperreports.engine.xml.JRReportSaxParserFactory.createParser(JRReportSaxParserFactory.java:108)
        at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createParser(JRXmlDigesterFactory.java:1316)
        at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createDigester(JRXmlDigesterFactory.java:1291)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:203)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:168)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:152)
        at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:150)

pleace sombody help me

Hitesh Kumar replied on Tue, 2012/02/21 - 8:56am

Thank you for your post Mr.Hossam Sadik,

 it help me alot.. now I am able to generate my report in EXCEL format and also in CSV format.. without making any change in .jrxml code, before this I was generating PDF file

...

I have a simple code which create a pdf page in new window with .jrxml file

JasperReport jasperReport;
JasperPrint jasperPrint;
connection=MyConnection.getConnection(); /*Myconnection class here is used to establish connection that i have created. */

ServletContext sc1 = getServletContext();
Map jasperParameter = new HashMap();


ServletContext sc = getServletContext();
String rPath = sc.getRealPath("/WEB-INF/jsp/jasper/report23.jrxml");/* change path according to your project */

jasperReport = JasperCompileManager.compileReport(rPath);
jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter, connection);

byte [] abc=JasperExportManager.exportReportToPdf(jasperPrint);

ServletOutputStream ob=response.getOutputStream();
response.setContentType("application/pdf");

ob.write(abc,0,abc.length);
ob.flush();
ob.close();

 

 

Carla Brian replied on Fri, 2012/04/27 - 11:40pm

This is really helpful. JasperReports provides the necessary features to generate dynamic reports, including data retrieval using JDBC as well as support for parameters, expressions, variables, and groups. - DR Marketing Group

Raji Lakshmi replied on Mon, 2012/06/18 - 1:28am in response to: ali askari

I am using netbeans IDE and jasper report in linux OS. I added all needed .jar files and My code is,

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
//import com.mysql.jdbc.Statement;
public class sampleclass
{
    public static void main(String g[])
    {
        try
        {
            Class.forName("com.mysql.jdbc.Driver").newInstance ();
            Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/testdb","root","ssgsoft");
            System.out.println("Connection Established!");
            InputStream input = new FileInputStream(new File("/home/ssg15/NetBeansProjects/sample/web/samplerep.jrxml"));
            JasperDesign jasperDesign = JRXmlLoader.load(input);
            System.out.println("Compiling Report Designs");
            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
            System.out.println("Creating JasperPrint Object");
            Map<String, String> parameters = new HashMap<String, String>();
            parameters.put("ReportTitle", "PDF JasperReport");
            System.out.println("Filling Report to File");
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, con);
            OutputStream output = new FileOutputStream(new File("/home/ssg15/NetBeansProjects/sample/web/samplerep.pdf"));
            JasperExportManager.exportReportToPdfStream(jasperPrint, output);
            System.out.println("Report Generation Complete");  
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }
}

 

 

 

I got the output as 

Connection Established!
18 Jun, 2012 11:54:12 AM org.apache.commons.digester.Digester error
net.sf.jasperreports.engine.JRException: org.xml.sax.SAXParseException: Document root element "jasperReport", must match DOCTYPE root "null".
SEVERE: Parse Error at line 2 column 405: Document root element "jasperReport", must match DOCTYPE root "null".
org.xml.sax.SAXParseException: Document root element "jasperReport", must match DOCTYPE root "null".
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.rootElementSpecified(XMLDTDValidator.java:1621)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1900)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:764)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1363)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl.java:1318)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3103)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:922)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    at org.apache.commons.digester.Digester.parse(Digester.java:1647)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:239)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:226)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:214)
    at sampleclass.main(sampleclass.java:41)
BUILD SUCCESSFUL (total time: 0 seconds)

 

What is worng in this? Any one can explian or can solve my problem, Please..

 

Shumon Mandal replied on Fri, 2012/07/20 - 2:39am

I am using ireport for reporting tool as plugin in netbeans 7.1.1.

I have designed the jrxml file through ireport but unable to compile it to any format when using it in a jsp page.m getting a blank  page output.

Here is my jrxml file code---------------

<?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="null" language="groovy" pageWidth="595" pageHeight="842" columnWidth="535" 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"/>

<style name="Title" forecolor="#FFFFFF" fontName="Arial" fontSize="26" isBold="true" pdfFontName="Helvetica-Bold"/>

<style name="SubTitle" forecolor="#666666" fontName="Arial" fontSize="18"/>

<style name="Column header" forecolor="#666666" fontName="Arial" fontSize="12" isBold="true"/>

<style name="Detail" fontName="Arial" fontSize="12"/>

<queryString language="SQL">

<![CDATA[select * from tma_dept where dept ='Civil';]]>

</queryString>

<field name="sl_no" class="java.lang.Integer"/>

<field name="fname" class="java.lang.String"/>

<field name="mname" class="java.lang.String"/>

<field name="lname" class="java.lang.String"/>

<field name="age" class="java.lang.Integer"/>

<field name="dob" class="java.sql.Date"/>

<field name="doj" class="java.sql.Date"/>

<field name="dept" class="java.lang.String"/>

<field name="perm_addr" class="java.lang.String"/>

<field name="contact_num" class="java.lang.Long"/>

<field name="alt_contact" class="java.lang.Long"/>

<field name="phone_num" class="java.lang.Long"/>

<field name="pre_addr" class="java.lang.String"/>

<field name="city" class="java.lang.String"/>

<field name="state" class="java.lang.String"/>

<field name="pin_code" class="java.lang.String"/>

<field name="gender" class="java.lang.String"/>

<background>

<band splitType="Stretch"/>

</background>

<title>

<band height="70" splitType="Stretch">

<image>

<reportElement x="-21" y="5" width="595" height="64"/>

<imageExpression class="java.lang.String"><![CDATA["wood.jpg"]]></imageExpression>

</image>

<staticText>

<reportElement style="Title" x="0" y="5" width="263" height="33"/>

<textElement verticalAlignment="Middle"/>

<text><![CDATA[Mahavir AutoVation]]></text>

</staticText>

<staticText>

<reportElement style="SubTitle" x="128" y="42" width="200" height="22" forecolor="#FFFFFF"/>

<textElement textAlignment="Right"/>

<text><![CDATA[Department Report]]></text>

</staticText>

</band>

</title>

<pageHeader>

<band splitType="Stretch"/>

</pageHeader>

<columnHeader>

<band height="36" splitType="Stretch">

<line>

<reportElement positionType="FixRelativeToBottom" x="0" y="35" width="555" height="1"/>

<graphicElement>

<pen lineWidth="0.5" lineColor="#999999"/>

</graphicElement>

</line>

<staticText>

<reportElement style="Column header" x="0" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[sl_no]]></text>

</staticText>

<staticText>

<reportElement style="Column header" x="32" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[fname]]></text>

</staticText>

<staticText>

<reportElement style="Column header" x="64" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[mname]]></text>

</staticText>

<staticText>

<reportElement style="Column header" x="96" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[lname]]></text>

</staticText>

<staticText>

<reportElement style="Column header" x="128" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[age]]></text>

</staticText>

<staticText>

<reportElement style="Column header" x="160" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[dob]]></text>

</staticText>

<staticText>

<reportElement style="Column header" x="192" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[doj]]></text>

</staticText>

<staticText>

<reportElement style="Column header" x="224" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[dept]]></text>

</staticText>

<staticText>

<reportElement style="Column header" x="256" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[perm_addr]]></text>

</staticText>

<staticText>

<reportElement style="Column header" x="288" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[contact_num]]></text>

</staticText>

<staticText>

<reportElement style="Column header" x="320" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[alt_contact]]></text>

</staticText>

<staticText>

<reportElement style="Column header" x="352" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[phone_num]]></text>

</staticText>

<staticText>

<reportElement style="Column header" x="384" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[pre_addr]]></text>

</staticText>

<staticText>

<reportElement style="Column header" x="416" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[city]]></text>

</staticText>

<staticText>

<reportElement style="Column header" x="448" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[state]]></text>

</staticText>

<staticText>

<reportElement style="Column header" x="480" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[pin_code]]></text>

</staticText>

<staticText>

<reportElement style="Column header" x="512" y="19" width="32" height="15"/>

<textElement/>

<text><![CDATA[gender]]></text>

</staticText>

</band>

</columnHeader>

<detail>

<band height="16" splitType="Stretch">

<line>

<reportElement positionType="FixRelativeToBottom" x="0" y="15" width="555" height="1"/>

<graphicElement>

<pen lineWidth="0.5" lineColor="#999999"/>

</graphicElement>

</line>

<textField>

<reportElement style="Detail" x="0" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{sl_no}]]></textFieldExpression>

</textField>

<textField>

<reportElement style="Detail" x="32" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{fname}]]></textFieldExpression>

</textField>

<textField>

<reportElement style="Detail" x="64" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{mname}]]></textFieldExpression>

</textField>

<textField>

<reportElement style="Detail" x="96" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{lname}]]></textFieldExpression>

</textField>

<textField>

<reportElement style="Detail" x="128" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{age}]]></textFieldExpression>

</textField>

<textField>

<reportElement style="Detail" x="160" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{dob}]]></textFieldExpression>

</textField>

<textField>

<reportElement style="Detail" x="192" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{doj}]]></textFieldExpression>

</textField>

<textField>

<reportElement style="Detail" x="224" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{dept}]]></textFieldExpression>

</textField>

<textField>

<reportElement style="Detail" x="256" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{perm_addr}]]></textFieldExpression>

</textField>

<textField>

<reportElement style="Detail" x="288" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{contact_num}]]></textFieldExpression>

</textField>

<textField>

<reportElement style="Detail" x="320" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{alt_contact}]]></textFieldExpression>

</textField>

<textField>

<reportElement style="Detail" x="352" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{phone_num}]]></textFieldExpression>

</textField>

<textField>

<reportElement style="Detail" x="384" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{pre_addr}]]></textFieldExpression>

</textField>

<textField>

<reportElement style="Detail" x="416" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{city}]]></textFieldExpression>

</textField>

<textField>

<reportElement style="Detail" x="448" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{state}]]></textFieldExpression>

</textField>

<textField>

<reportElement style="Detail" x="480" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{pin_code}]]></textFieldExpression>

</textField>

<textField>

<reportElement style="Detail" x="512" y="0" width="32" height="15"/>

<textElement/>

<textFieldExpression class="java.lang.String"><![CDATA[$F{gender}]]></textFieldExpression>

</textField>

</band>

</detail>

<columnFooter>

<band height="45" splitType="Stretch">

<line>

<reportElement positionType="FixRelativeToBottom" x="0" y="3" width="555" height="1"/>

<graphicElement>

<pen lineWidth="0.5" lineColor="#999999"/>

</graphicElement>

</line>

</band>

</columnFooter>

<pageFooter>

<band height="20" splitType="Stretch">

<textField>

<reportElement style="Column header" x="433" y="0" width="80" height="20"/>

<textElement textAlignment="Right">

<font size="10" isBold="false"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>

</textField>

<textField evaluationTime="Report">

<reportElement style="Column header" x="513" y="0" width="40" height="20"/>

<textElement>

<font size="10" isBold="false"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>

</textField>

<textField pattern="EEEEE dd MMMMM yyyy">

<reportElement style="Column header" x="0" y="0" width="197" height="20"/>

<textElement>

<font size="10" isBold="false"/>

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[new java.util.Date()]]></textFieldExpression>

</textField>

</band>

</pageFooter>

<summary>

<band splitType="Stretch"/>

</summary>

</jasperReport>

 

Here is my jsp code------------------

 

<%@page import="net.sf.jasperreports.view.JasperViewer"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

    pageEncoding="ISO-8859-1"%>

<html>

 

<body >

     <%@page import="java.lang.*"%>                   

    <%@page import= "java.sql.Connection"%>

    <%@page import= "java.sql.DriverManager"%>

    <%@page import= "java.sql.*"%>

    <%@page import= "java.util.HashMap"%>

    <%@page import= "net.sf.jasperreports.engine.JRExporterParameter"%>

    <%@page import= "net.sf.jasperreports.engine.JasperCompileManager"%>

    <%@page import= "net.sf.jasperreports.engine.JasperFillManager"%>

    <%@page import= "net.sf.jasperreports.engine.JasperPrint"%>

    <%@page import= "net.sf.jasperreports.engine.JasperPrintManager"%>

    <%@page import= "net.sf.jasperreports.engine.JasperReport" %>

    <%@page import= "net.sf.jasperreports.engine.export.*"%>

    <%@page import= "net.sf.jasperreports.engine.JasperExportManager"%>

    <%@page import= "net.sf.jasperreports.engine.JREmptyDataSource"%>

    <%@page import= "net.sf.jasperreports.engine.JRException"%>

 

    <%

         String input = "./report/dept_report.jrxml";

         String output = "./report/dept_report.html";

 

        Connection con = null;

        JasperReport jasperReport;

        JasperPrint jasperPrint;

        try

           {

                Class.forName("com.mysql.jdbc.Driver");

                con = DriverManager.getConnection("jdbc:mysql://localhost:3306/tma","root","root");

                out.println("inside con");

                HashMap jasperParameter = new HashMap();

                out.println("inside hash map");

                jasperReport = JasperCompileManager.compileReport(input);

                out.println("inside jasperReport"+jasperReport);

                jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter, con);

                JasperExportManager.exportReportToHtmlFile(jasperPrint,output);

                //JasperViewer.viewReport(jasperPrint);

                //JRXlsExporter exporter = new JRXlsExporter();

                //exporter.exportReport();

 

           }

                 catch (Exception ex) {

                                ex.printStackTrace();

                            }

                            finally {

                                con.close();

                            }

 

 

 

 

    %>

        </body>

 

 

 

</html>

KINDLY SUGGEST ME WHERE AM I WRONG? 

Shumon Mandal replied on Fri, 2012/07/20 - 2:48am

I am using ireport in netbeans 7.1.1 as plugin for report designing.I got the jrxml file but unable to show it in the browser and compiling in jsp. m getting a blank page output?

Swapnil Shirsat replied on Sat, 2012/08/25 - 8:42am

I am getting this error when i am trying to run the above code
please help me out.
I am using eclipse IDE and ireport 4.7.0 tool


Exception in thread "main" net.sf.jasperreports.engine.JRException: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:247)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:226)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:214)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:168)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:152)
    at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:151)
    at demo.main(demo.java:45)
Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
    at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.arrangeCapacity(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipString(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.apache.commons.digester.Digester.parse(Digester.java:1647)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:239)
    ... 6 more

Steve Kalenga replied on Thu, 2012/09/06 - 2:51am

hi i did use this tutorial

i using jdevloper 11 release 2 adf and oracle 11g

when i run the report it return just an empty pdf,html and excel

the code have the jasperparameter underline with message "unchecked conversion from hashmap to <string,object> unsound but tolorated"

 

could anyone check my code and tell me where did i miss 

 package deployPro.view;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import java.io.*;
import java.util.*;
import java.sql.Connection;
import java.sql.SQLException;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.sql.DataSource;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;
import java.sql.DriverManager;

@ManagedBean(name="CollegeReportsBean")
@RequestScoped
public class reportsClass {
    
    /* JasperReport is the object
    that holds our compiled jrxml file */
    JasperReport jasperReport;
    
    
    /* JasperPrint is the object contains
    report after result filling process */
    
    
    JasperPrint jasperPrint;
    
    public reportsClass() {
    }
     
    
    public static Connection establishConnection() throws ClassNotFoundException {
    Connection connection = null;
    try
    {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    String oracleURL = "jdbc:oracle:thin:@localhost:1521:xe";
    connection = DriverManager.getConnection(oracleURL,"username","password");
    connection.setAutoCommit(false);
    }
    catch(SQLException exception)
    {
    exception.printStackTrace();
    }
    return connection;
     
    }
            
    public void welcome(ActionEvent actionEvent)  throws FileNotFoundException, JRException, NamingException, SQLException, IOException, ClassNotFoundException {
       
       
        // connection is the data source we used to fetch the data from
        
        Connection connection = establishConnection();
        
        // jasperParameter is a Hashmap contains the parameters
        // passed from application to the jrxml layout
        
        
       HashMap jasperParameter;
        jasperParameter = new HashMap();
        
        // jrxml compiling process
        
        jasperReport = JasperCompileManager.compileReport("C:\\JDeveloper\\mywork\\CollegeInformationSystem\\CollegeViewController\\report2.jrxml");
        
        
        // filling report with data from data source
        
        
        jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter, connection);
        
        
        // exporting process
        // 1- export to PDF      

        JasperExportManager.exportReportToPdfFile(jasperPrint, "C://sample_report1.pdf");
        
        // 2- export to HTML
        
        JasperExportManager.exportReportToHtmlFile(jasperPrint, "C://sample_report.html" );


        // 3- export to Excel sheet
        
        JRXlsExporter exporter;
        exporter = new JRXlsExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "C://simple_report.xls" );
        
        exporter.exportReport();
        
        
    }
    
    
    
}

 

Virendr Patidar replied on Tue, 2012/10/02 - 12:07am

Plzzzz

any one can send complete code for jasper report and how i compile it

Virendra341@gmail.com 

Farooq Shaikh replied on Fri, 2012/10/05 - 12:53am

HI ALL...

  

Shumon Mandal: if u got the solution let me kno .. am using jsp to call jrxml .. 

farooqsha27@gmail.com

Here is my jsp code------------------

<%@page import="net.sf.jasperreports.view.JasperViewer"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<html>

<body >

<%@page import="java.lang.*"%>

<%@page import= "java.sql.Connection"%>

<%@page import= "java.sql.DriverManager"%>

<%@page import= "java.sql.*"%>

<%@page import= "java.util.HashMap"%>

<%@page import= "net.sf.jasperreports.engine.JRExporterParameter"%>

<%@page import= "net.sf.jasperreports.engine.JasperCompileManager"%>

<%@page import= "net.sf.jasperreports.engine.JasperFillManager"%>

<%@page import= "net.sf.jasperreports.engine.JasperPrint"%>

<%@page import= "net.sf.jasperreports.engine.JasperPrintManager"%>

<%@page import= "net.sf.jasperreports.engine.JasperReport" %>

<%@page import= "net.sf.jasperreports.engine.export.*"%>

<%@page import= "net.sf.jasperreports.engine.JasperExportManager"%>

<%@page import= "net.sf.jasperreports.engine.JREmptyDataSource"%>

<%@page import= "net.sf.jasperreports.engine.JRException"%>

<%

String input = "./report/dept_report.jrxml";

String output = "./report/dept_report.html";

Connection con = null;

JasperReport jasperReport;

JasperPrint jasperPrint;

try

{

Class.forName("com.mysql.jdbc.Driver");

con = DriverManager.getConnection("jdbc:mysql://localhost:3306/tma","root","root");

out.println("inside con");

HashMap jasperParameter = new HashMap();

out.println("inside hash map");

jasperReport = JasperCompileManager.compileReport(input);

out.println("inside jasperReport"+jasperReport);

jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter, con);

JasperExportManager.exportReportToHtmlFile(jasperPrint,output);

//JasperViewer.viewReport(jasperPrint);

//JRXlsExporter exporter = new JRXlsExporter();

//exporter.exportReport();

}

catch (Exception ex) {

ex.printStackTrace();

}

finally {

con.close();

}

%>

</body>

</html>

Farooq Shaikh replied on Fri, 2012/10/05 - 12:55am in response to: Shumon Mandal

hi .. if u got the solution .. pl.z let me kno ..

Alexandre Zykov replied on Fri, 2013/08/02 - 2:52pm

I have the code similar to the article and a set of import directives:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.InetAddress;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.ParsePosition;
import java.util.HashMap;
import java.util.Map;

import org.apache.poi.ss.usermodel.Font;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
import net.sf.jasperreports.engine.JRExporterParameter;

. . .

  File jrxmlFile = new File(jrxmlFileName);

  JasperReport jasperReport = JasperCompileManager.compileReport(jrxmlFileName);
  java.sql.Connection reportConnection = SessionLogger.getConnection();
  JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, reportConnection);

  JRXlsExporter exporter = new JRXlsExporter();
  exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
  exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, xlsFileName);

  //Excel specific parameter
  exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
  exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);
  exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
  exporter.setParameter(JRXlsExporterParameter.IGNORE_PAGE_MARGINS,

Boolean.TRUE);
  exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
  exporter.exportReport();

. . .

The code works fine with Jasper Library 3.7.6. It doesn't compile with 5.2.0, 5.1.0 or 4.5.0 giving the error message:
omr515.java:401: cannot find symbol
symbol  : method fillReport(net.sf.jasperreports.engine.JasperReport,java.util.Map<java.lang.String,java.lang.String>,java.sql.Connection)
location: class net.sf.jasperreports.engine.JasperFillManager
  JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, reportConnection);
. . . 

I cannot find any example how JasperFillManager.fillReport can be used to create the JasperPrint for Excel files in the sample folders for the 5.2.0, 5.1.0 or 4.5.0 Jasper Libraries.

Mujahid Masood replied on Wed, 2013/12/25 - 8:08am

Hi,

 How can I use the printer facility of Jasper report in web app.Currently I am using it, when application is deployed on my local machine, print functionality is working fine but when I deploy it on portal server of Remote machine, it stops the printing.


Any help or idea in this regard would be appreciated.


Thanks

Mujahid


Soumya Bardhan replied on Tue, 2014/01/14 - 5:29pm

Hi,


Can you please tell me how to password protect the excel file exported in the example?

Any other version of jasper reports will also be fine.


Thanks,

Soumya Bardhan


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.