Getting started with JasperReports // Printing reports from your java app (Part III) 1

In the past 2 entries (Part I and Part II) we learnt how to develop a basic report and how to fill it with data from a database with a jdbc connector. Now we will learn how to call a report from within a Java application and how to set some basic parameters.

The most important thing when running your reports from within a java application is to have all the necessary jar libraries available from your classpath. The basic ones for running the sample report will be commons-logging-*.jar, commons-collections-*.jar, jasperrerports-*.jar and yourJDBCconnector.jar. All of them (except the jdbc connector) can be found in the iReport ./lib directory.

Next thing you’ll need is a compiled version of your report. This you can find in the same folder you saved your report when you developed it in iReport. It will have the same name as the report source but the extension will be .jasper.

Now we are ready to call our report from Java. The most important class now is JasperPrint. The basics for this class are to specify a report and a datasource to fill it. In the following lines you’ll find the code to run our report. The example simply creates a postgresql datasource and gives the path to the compiled jasper file. Then with some simple parameters it specifies the number of copies and tells the program to print the report.

Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “Getting started with JasperReports // Printing reports from your java app (Part III)

  • chena


    i’m using Jasper Report to generate report.i’m usin hibernate.while retrievin the data from database

    for(int i=0;i<lOptionList.size();i++)


    String Answer = (String)OptionList.get(i);


    System.out.println(“lStr : “+Answer);


    here the value is printed in the eclipse console as male n female.

    And in the xml

    <parameter name=”Report_Ans” class=”java.lang.String”/>


    <band height=”100″>


    <reportElement x=”28″ y=”8″ width=”100″ height=”29″/>

    <textFieldExpression class=”java.lang.String”>






    i’m not able to retrieve the two values in the PDF

    report generating.

    i tink the problem is to retrieve the two values in xml.

    pls help me