Jasper Reports Tutorial

Posted: November 23, 2011 in Java, Reports
Tags: , ,

Jasper Reports is one of the most popular and most used open source reporting engine in the industry today. Its completely written in Java and can use data coming from any ‘datasource’  and generate reports in PDF, EXCEL and HTML.

Prerequisites for this tutorial

  1. Download and install iReports from http://jasperforge.org/projects/ireport                      (We use this to create the report template/layout) and this website will give you a  very very clear idea on how to design a report template. Trust me, its easy. It’s easy to understand it from their own website rather me trying to explain it in words.
  2. Download and install MySQL
  3. Have the following jar files in your classpath

commons-beanutils-1.7.jar

commons-collections-3.1.jar

commons-digester-1.8.jar

commons-lang-2.1.jar

commons-logging-1.1.jar

iText-2.1.1.jar

jasperreports-1.0.3.jar

mysql-connector-java-5.0.4-bin.jar

Note: The template that we create using iReport tool will be saved with extension .jrxml

Create a folder jrxml in your project and save/copy the template you designed here.

Create a folder report in your project and this is where your PDF/EXCEL report will be saved

Before we go further, we need to populate the data in the database so that we can fetch it and display it on the report. (Who would like to see a empty PDF report? In case, if you get a empty PDF report, then your must have forgotten to  add iText-2.1.1.jar to the classpath..provided your query works)

Execute the following scripts in MySQL Browser

create table Employee(
ID                 VARCHAR(4) NOT NULL,
First_Name         VARCHAR(10),
Last_Name          VARCHAR(10),
Start_Date         DATE,
End_Date           DATE,
Salary             DECIMAL(8,2),
City               VARCHAR(10),
Description        VARCHAR(15)
)

INSERT into Employee values
(’06’,’Suhas’,’Saheer’,
to_date(‘20071213′,’YYYYMMDD’),
to_date(‘20701213′,’YYYYMMDD’),
52500.56,
‘MUNICH’,
‘Programmer’)

Since this is your first application, lets make it simple.
We need to fetch the first_name and last_name from the employee table and show it on a PDF report named EmployeeReport.pdf

So the query for fetching the records to be displayed on the report is

select First_Name, Last_Name from employee e

Where to we need to provide this query?
Either we can provide it in the .jrxml file we created or in our invoking method(java class)

In this tutorial, we are talking about the case where we mention the query in the .jrxml file itself

EmployeeReport.jrxml

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE jasperReport PUBLIC “//JasperReports//DTD Report Design//EN”
http://jasperreports.sourceforge.net/dtds/jasperreport.dtd”&gt;
<jasperReport name=”EmployeeReport_SuhasJavaBlog”>
<queryString>
<![CDATA[select First_Name, Last_Name from employee e]]>
</queryString>
<field name=”First_Name” />
<field name=”Last_Name” />
<title>
<band height=”50″>
<staticText>
<reportElement x=”0″ y=”0″ width=”180″ height=”15″/>
<textElement/>
<text><![CDATA[Jasper Report - SuhasJavaBlog]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height=”30″>
<staticText>
<reportElement x=”0″ y=”0″ width=”69″ height=”24″ />
<textElement verticalAlignment=”Bottom” />
<text>
<![CDATA[First Name: ]]>
</text>
</staticText>
<staticText>
<reportElement x=”140″ y=”0″ width=”79″ height=”24″ />
<text>
<![CDATA[Last Name: ]]>
</text>
</staticText>
</band>
</pageHeader>
<detail>
<band height=”30″>
<textField>
<reportElement x=”0″ y=”0″ width=”69″ height=”24″ />
<textFieldExpression>
<![CDATA[$F{First_Name}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x=”140″ y=”0″ width=”69″ height=”24″ />
<textFieldExpression>
<![CDATA[$F{Last_Name}]]>
</textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>

Note the highlighted text in the above template. (Thats our SQL query to fetch the records)

Now let’s take a look the Java code for generating the report. (We use Jasper API for this)

1. Establish a connection to the MySQL database :

Class.forName(“com.mysql.jdbc.Driver”);
conn = DriverManager.getConnection(“jdbc:mysql://localhost:3306/test?user=root&password=root”);

2. Read the .jrxml report template you have designed and create a JasperDesign Object which represent the report design :

InputStream input = new FileInputStream(new File(“jrxml/BasicReport.jrxml”));
JasperDesign jasperDesign = JRXmlLoader.load(input);

3. Now compile the report design file to create a JasperReport object. The compilation of the report design file validates the JasperReports XML file (EmployeeReport.jrxml) with the jaspereports.dtd DTD and converts the report expressions into a ready-to-evaluate form :

JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);

4. To view this, generate a JasperPrint document, which may be viewed, printed or exported to other formats, from the compiled report design :

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);

In this example,  we don’t have any parameters to pass.

Hence we re-write this as

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);

5. A JasperReports report may be exported to a XML file, a PDF file, an HTML file, a CSV file, or an Excel XLS file; to export the JasperReports report we’ve just generated to a PDF file, use this:

 OutputStream output = new FileOutputStream(new File(“jrxml/EmployeeReport.pdf”));
JasperExportManager.exportReportToPdfStream(jasperPrint, output);

That’s it. You have done it. You just need to execute this method and you have your report ready under the ‘reports’ folder in your project

ReportGenerator.java

package de.suhas.jasper;

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;

public class ReportGenerator {

Connection conn;

public void generateReport() {

try {
Class.forName(“com.mysql.jdbc.Driver”);
conn = DriverManager.getConnection(“jdbc:mysql://localhost:3306/test?user=root&password=root”);
System.out.println(“Loading Report Designs”);
InputStream input = new FileInputStream(new File(“jrxml/BasicReport.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, conn);

//Exporting the report
OutputStream output = new FileOutputStream(new File(“jrxml/catalog.pdf”));
JasperExportManager.exportReportToPdfStream(jasperPrint, output);

System.out.println(“Report Generation Complete”);
conn.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (JRException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
new ReportGenerator().generateReport();
}
}

Hope you guys have understood the art of creating reports using Jasper API and iReports.

Would love to hear from you guys if this was the slightest help to you.
Also feel free to drop in a reply for any queries related to Jasper Reports

About these ads
Comments
  1. supriya says:

    if database is already created and i have to use that database table to generate pdf in servlet , how we can do this.and also how to get value from two database table using join

    • supriya says:

      please reply soon……….

    • ShamanOfJava says:

      Hi Supriya,

      Create an instance of ReportGenerator.java in your serlver doPost() method.
      In ReportGenerator.java, we connect to the database using the code

      Class.forName(“com.mysql.jdbc.Driver”);
      conn = DriverManager.getConnection(“jdbc:mysql://localhost:3306/test?user=root&password=root”);

      Replace your DB connection URL here.

      Share with me your table details and I will reply back with how to join them.

      Have a good day ahead. :)

  2. supriya says:

    Table project

    ‘id’, ‘varchar(20)’,
    ‘pname’, ‘varchar(20)’,
    ‘pmanagername’, ‘varchar(20)’,
    ‘dmname’, ‘varchar(20)’,
    ‘vpname’, ‘varchar(20)’,
    ‘sqaname’, ‘varchar(20)’,
    ‘prmanagername’, ‘varchar(20)’,
    ‘prexeclocation’,’varchar(20)’,
    ‘techofproject’, ‘varchar(20)’,
    ‘lifecycle’, ‘varchar(20)’,
    ‘releasetype’, ‘varchar(20)’,
    ‘modifydate’, ‘date’,
    ‘statu_s’, ‘enum(‘open’,’closed’)’,

    Table nclist

    ‘id’, ‘bigint(20)’, ‘NO’, ‘PRI’,
    ‘AuditReport_id’, ‘bigint(20)’,
    ‘AuditFinding’, ‘varchar(100)’,
    ‘ProcessReference’, ‘varchar(100)’,
    ‘ActionPlanned’, ‘varchar(100)’,
    ‘TargetClosureDate’, ‘date’,
    ‘PersonResponsible’, ‘varchar(100)’,
    ‘NCStatus’, ‘varchar(100)’,
    ‘ActualClosureDate’, ‘date’,
    ‘Remarks’, ‘varchar(200)’,

    please help me joining these two table contents by using join query using jasper in servlet only

  3. supriya says:

    i have kept all my jasper and .jrxml file in WEB-INF of web content folder…. and for single table it is working .. here is the code below……….

    package AuditSummarypkg;

    import net.sf.jasperreports.engine.JRResultSetDataSource;
    import net.sf.jasperreports.engine.JasperCompileManager;
    import net.sf.jasperreports.engine.JasperFillManager;
    import net.sf.jasperreports.engine.JasperPrint;
    import net.sf.jasperreports.engine.JasperPrintManager;
    import net.sf.jasperreports.engine.JasperExportManager;
    import net.sf.jasperreports.engine.JasperReport;
    import net.sf.jasperreports.engine.design.JasperDesign;
    import net.sf.jasperreports.engine.xml.JRXmlLoader;
    import net.sf.jasperreports.engine.JRException;
    import java.io.*;
    import java.net.*;
    import java.sql.*;
    import java.util.*;
    import java.sql.*;
    import java.io.File;
    import java.util.Date;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import net.sf.jasperreports.engine.*;
    import net.sf.jasperreports.view.JasperViewer;
    import net.sf.jasperreports.engine.JasperPrintManager;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.ServletOutputStream;
    import java.io.PrintWriter;
    import java.io.IOException;
    public class ASRServlet extends HttpServlet{

    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException{

    Connection conn = null;
    Statement st = null;
    ResultSet rs = null;
    try{
    Class.forName(“com.mysql.jdbc.Driver”);
    conn=DriverManager.getConnection(“jdbc:mysql://localhost:3306/asr_database”, “root”, “root”);
    st=conn.createStatement();
    rs =st.executeQuery(“select * from project where pname=’ASR'”);

    System.out.println(“The context path is >>>>>>>>>> ” + request.getContextPath());

    String src= “/ReportTB.jrxml”;
    net.sf.jasperreports.engine.design.JasperDesign jDesign = net.sf.jasperreports.engine.xml.JRXmlLoader.load(src);
    JasperReport jReport = net.sf.jasperreports.engine.JasperCompileManager.compileReport(jDesign);

    Map p1 = new HashMap();

    ByteArrayOutputStream baos =new ByteArrayOutputStream();
    response.setContentType(“application/pdf”);
    //response.setContentType(“application/.xls”);
    JasperDesign design = JRXmlLoader.load(src);

    JasperReport report = JasperCompileManager.compileReport(design);
    JRResultSetDataSource jasperReports = new JRResultSetDataSource(rs);
    JasperPrint print = JasperFillManager.fillReport(report, new HashMap(), jasperReports);

    //JasperPrint jPrint= JasperFillManager.fillReport( jReport,null,conn );

    net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(print,baos);
    //net.sf.jasperreports.engine.JasperExportManager.exportReportToXmlStream(jPrint,baos);
    response.setContentLength(baos.size());
    ServletOutputStream out1 = response.getOutputStream();
    baos.writeTo(out1);
    out1.flush();

    rs.close();
    st.close();
    conn.close();
    }
    catch(Exception e)
    {
    System.out.println(e.getMessage());
    }

    }
    }

    • ShamanOfJava says:

      Inorder to join two tables, you need to have a common-field in both tables.
      Based on which field you want to join these 2 tables?

  4. supriya says:

    ya i have common field which is ” id ” in both the tables…….

    can u help me generating particular column using jasper tool i.e iReport tool…as i have generated particular row,,, but unable to generate particular column.what steps are to be followed….

    please reply……..

  5. supriya says:

    can you please help me………….for the above questions.

  6. ShamanOfJava says:

    Please go through the below link to understand about JOINS (Its very simple)

    http://www.w3schools.com/sql/sql_join.asp

    Regarding the column issue, what exactly is your issue?
    Are you getting a row generated with all columns empty or with only specific columns empty?

  7. supriya says:

    regarding column issue is that…. if i want particular column to be generated then it is giving error… means if i am writing query in iReport tool like select id,pname from project;
    it is giving error, that other column fields are missing.
    and if i am writing select * from project;
    it is running successfully in i report tool

  8. supriya says:

    Oh my problem is not that, how should i write the query of join… but how should i use in the coding by deploying jasper in servlet in Eclipse… the above code which i have sended is fetching data from single table.and i want to use multiple table

  9. supriya says:

    i want to generate report using multiple table using jasper in servlet.. i tried but geeting error. i am not able to generate subreport from a table.

  10. ShamanOfJava says:

    try this

    Select * from project p join nclist n on p.id = n.id;

  11. jona says:

    Hi,
    I want to generate multiple reports in a pdf or XL using jasper batch export, I will hit the DB and get all the data in a single query for all the reports, I need iterate through the java object to fill the jasperprint object instead directly querying from the DB, is there any API available to fill the data from an java collection object by JasperFillManager?

    Thanks,

    jona

  12. mojo says:

    Hi,

    I have followed everything step-by-step, but I get an error:
    java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester

    at line:
    JasperDesign jasperDesign = JRXmlLoader.load(input);

    Supriys mentioned something about a WEB-INF folder. Do I have to have a web server setup? I am creating a Point-Of-Sale software package that runs from a Java Application. Sales reports will run on the admin machine, so I don’t really want a web server.

    Thank you for the tutorial! This is the best written tutorial onJasperReports that is currently on the net.

    You are a star

    • 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 parameters = new HashMap();
      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..

  13. smartabhi says:

    supriya says:
    March 21, 2012 at 1:36 PM

    ya i have common field which is ” id ” in both the tables…….

    can u help me generating particular column using jasper tool i.e iReport tool…as i have generated particular row,,, but unable to generate particular column.what steps are to be followed….

    please reply……..

    Solution:

    In IReport Query Editor use below query as reference
    “SELECT column_name(s)
    FROM table_name1
    INNER JOIN table_name2
    ON table_name1.column_name=table_name2.column_name”

    Now Select Read fields in IReport Designer. Once fields are loaded, In Designer mode DRAG those fields in report. and Save your report.

    Inorder to Compile and all use code written by ShamanOfJava

  14. pradhumna says:

    L2: InputStream input = new FileInputStream(new File(“jrxml/BasicReport.jrxml”));
    L3: JasperDesign jasperDesign = JRXmlLoader.load(input);

    Step-2 that u mentioned should it be EmployeeReport.jrxml OR BasicReport.jrxml ?

  15. vaibhav says:

    Hey any one please tell me how to insert a data dynamically into a jasper reports table….

    i have created a jasper report table…but dont know about how to give a query at runtime and generate a table..

  16. gouthami says:

    hi ,i am having value 37.006 ,to show on report like 37.00 i’m fixing the field pattern to two decimals and ireport is showing me as 37.01 but i want it to show 37.00 only is there a way…please reply

  17. piolo says:

    where to download all required jars?

  18. srinu says:

    i am developing normal java class for retreiving data from database and developing jrxsl file for generating the reports. after developing jrxsl files i am converting those files into jrxml files by using java class.After getting jrxml file, i am giving this file as input to JasperSoft IReportEngine tool.i am executing all java classes perfectly. but in JasperSoft IReportEngine i am not getting the data?
    if you know the solution just mail to srinivas.0742@gmail.com..
    Thank you so much..

  19. Bindu says:

    Hi all,
    I am having a linkedlist of beans which I have to use in my jrxml file to create a table of bank book with multiple columns like voucher date,voucher number etc.Can anyone please help me out how i can proceed as I am new to jasper reports.

    • ShamanOfJava says:

      Why don’t you create a single custom DTO class to hold all your report fields ?
      You just need to pass the List to the report genrator.

  20. Vinayak says:

    hi, I am getting an Error while compiling report source file.

  21. I have learn some excellent stuff here. Definitely value bookmarking for revisiting.

    I wonder how so much attempt you set to create any such magnificent informative site.

  22. Howdy! This post could not be written much better! Looking at this post reminds me of my previous roommate!
    He always kept preaching about this. I’ll forward this post to him. Fairly certain he will have a very good read. Many thanks for sharing!

  23. Go Here says:

    I’ve learn some excellent stuff here. Definitely worth bookmarking for revisiting. I wonder how so much attempt you put to create such a great informative web site.

  24. basker says:

    i need servlet example exactly ? using jrxml

  25. Anurag Patel says:

    I have created simple reports using ireports 4.7, When I compile this into ireports then it is successfully running but when I integrate this in java application then it is showing report but all values is “null”
    below is my action class and struts file code. (struts & hibernate)

    package Actions;

    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Set;

    import net.sf.jasperreports.engine.JREmptyDataSource;
    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 Dao.UnpaidListDao;
    import POJOS.AddCattlePOJO;
    import POJOS.AddFeesCollectionPOJO;
    import POJOS.AddOwnerInfoPOJO;
    import POJOS.UnpaidListPOJO;

    import com.opensymphony.xwork2.ActionSupport;

    public class FeesCollectDetails extends ActionSupport{

    DateFormat currDate = new SimpleDateFormat(“dd/MM/yyyy”);
    private String zone;
    private List zonewizeOwnerList = new ArrayList();
    private List cattlesList = new ArrayList();
    private List feescollectList = new ArrayList();
    //private List list = new ArrayList();
    private List list = new ArrayList();

    public String getFeesDetail()
    {

    System.out.println(“In UnpaidList… getZonewiseOwnerinfo”);
    //List listOwner = new ReportsForPenaltyZonewiseDAO().getZonewiseOwner(zone);
    Set zoneList = new UnpaidListDao().getAllZoneList();
    for (String zone : zoneList)
    {
    zonewizeOwnerList = new UnpaidListDao().getZonewiseOwner(zone);
    System.out.println(“after zone passing into action”+zonewizeOwnerList);
    for(AddOwnerInfoPOJO b : zonewizeOwnerList)
    {
    AddCattlePOJO cattle = new UnpaidListDao().getZonewiseCattle(b.getLicenceNumber());
    if(cattle!=null)
    cattlesList.add(cattle);
    AddFeesCollectionPOJO fees = new UnpaidListDao().getZonewiseFeesCollection(b.getLicenceNumber());
    if(fees!=null)
    feescollectList.add(fees);
    }

    System.out.println(“feescollectList”+feescollectList);
    System.out.println(“Done”);
    System.out.println(“Success”);

    }
    /* try {
    JasperCompileManager.compileReportToFile(“/Jasper/report6.jrxml”,”/Jasper/report6.jasper”);
    } catch (Exception e) {
    e.printStackTrace();

    }*/
    return SUCCESS;
    }

    public List getFeescollectList() {
    return feescollectList;
    }

    public void setFeescollectList(List feescollectList) {
    this.feescollectList = feescollectList;
    }

    }

    ————————————————————————————–

    struts code

    /Jasper/report6.jasper
    feescollectList
    PDF

    Any one give me solution for above problem.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s