Building Your First iReport
Welcome to the Post 2. In previous
article we went through the Introduction of iReports and its basic structure. In this article, let us create a simple iReport in iReport
Designer .
Follow the instructions and install Jasper
Report Server in your machine .
After installation you w’ll get Jaspersoft
Designer in your program list :
Select Start iReport
Designer from list , now we w’ll get a screen like this :
Now to create a new report go to
File and select new , now a window w’ll pop up like this, designer gives a
variety of reports selection , but let’s select a simple template for now ,
select Report in left column and Blank A4 from right box.
Now click Open This Template from bottom and you w’ll get a window like this
:
Give a Report name and Location for your report and click next .
Now click Finish , and we are done
with creating a template .
Creating a data source or a database
connection used to fill the report.
Now we w’ll setup database settings
and connections to get dynamic data for our report .
To create the new connection in
iReport, open the datasources/connections dialog by clicking its icon in the
tool bar.
After clicking on this icon you w’ll
get a window like this : -
Click new from right side to create
a new db connection :
Select a data source from a
list of Datasources , lets select Database JDBC connection
fro now :
Click next , and add all the
connection details :
Click save , now we are all set with
our database connection .
Now we need some data from
database to display on the report , lets create a query to fetch data from
database , to open query editor click on the icon as shown in picture below :
Clicking on this icon you w’ll get a
query editor like this :
Now time to create a query to get
required data .Once you are done with SQL query your window w’ll look like this
:
As you type the query, iReport
executes it to extract all the fields (columns) available in the query. The
fields are listed on the bottom portion of the window. If there is an error in
the SQL, you'll get a message that explains what's wrong. When the query is
valid, click OK. Now lets create some fields in our report to generate some pages
.
To print the value of a field in the report, drag a field object from the report inspector to the design view.
To add other elements (such lines or
labels), drag them from the palette Window :
If you don’t get the window select
it from Window in menu :
Now its all you need to design your
report , after design is done your report w’ll look like this :
To see the resulting report go to
Preview and see what you created :
and here we go :
Congratulations, we have just
created your first report. In next post that is post 3 we w'll cover Datasets and Table component in Jasper Reports
Comments
Post a Comment