Sep 20, 2015

Using html in jasper ireport

Sometimes we required to use html tag in jasper ireport.

we can use html in jasper using two methods.

  •  Using Html component 

            You can use Html component to get required output of html script.

            Drag and drop Html component and select HTML Content Exp.  property.

            Provide appropriate Expression and click on Preview to run the report.

  • Using Markup property of a Text Field

           You can also use Markup Property of Text Field to show text in html scipt.

           Select a Text Field and goto Markup Property 

           Select html from the list 

           Provide appropriate html Scipt in Text Field Expression of Text Field.

           Click on Preview to run the report.

Sep 18, 2015

Date format and custom date format in jasper ireport

Date format

There are many date format available in jasper ireport to choose from.

To choose from date format available in jasper ireport select Text Field.

  • Go to Pattern  Property of selected Text Field.

  • Click on right icon to select from list.

  • You will see Different Category , select Date Category .

  • Now different type of Pattern is available for date , select required pattern and click on OK.

          For example I have select Pattern dd/MM/yyyy

  • Now Click on Preview to run your report.

You can change Pattern at any part of time as per your requirement.

Custom Date format

Sometimes it is required to change date format dynamically.
You can change date format run time dynamically .

  • For same you have to create a Parameter of type java.lang.String and its value can be change at run time.

For example I have created a Parameter DateFormat of type java.lang.String.

  • Go to Pattern Expr.  Property of selected Text Field.

  • Click on right icon to Select Parameter.

  • Now Click on Preview to run your report.
          Pass parameter value as per java recommender Date Format.

Using java SimpleDateFormat

You can also use java SimpleDateFormat to required date format.

Add following expression in Text Field Expression

new SimpleDateFormat(Date_Format).format(Database_field)

where Date_format is Pattern value as per your requirement 
and Database_field is database field which need to be formatted(must be Date data Type).

textField with pattern performers faster than new SimpleDateFormat("Date_Format").format("Database_field"). 
It's important when you have deal with huge reports.

Sep 17, 2015

Use IN clause of sql in jasper ireport

Sometime it is necessary to pass IN clause of sql in jasper ireport.

You can use following syntax

select ... where $X{IN, database_column_name, parameter_name}

parameter_name  is a parameter name  of type Collection or array.
Your parameter to be of type java.util.Collection or java.util.List.

database_column_name is database column name.

With the $X{} syntax, the word IN is the name of the function (the other choice is  NOT IN).

Sep 15, 2015

Create New database connection or datasource in ireport

Following step is required to create New database connection.

1.) You have to click on Report Datasources.

   Selected Connection/Datasource is shown just beside Report Datasources.

2.) To create New Connection/Datasource click on Report Datasources

New Dialog Box will be opened which contains all Connections/Datasources Name

3.) Click on New to create new Connection or click on Modify to modify available    Connection/Datasources .

When you will click on New , a new dialog box will open to select Datasource Type.

4.) Select Database JDBC connection to create database Connection and click Next.

5.)Provide Connection name.

6.) Select JDBC Driver from list

7.) Now select Oracle Driver from List

      If you have not installed Oracle Driver then Install Oracle Driver.

8.) Now provide JDBC URL ,Username, password and select Save password check box to save the password.

 9.)Now click on Test  to test the connection .

Once you connection test is successful then click on Save to save the Connection.

10.)When you save the connection , Connection will  appear in Connections/Datasources name

Now click on Close to close the dialog box .

Now New Created is set as default connection .

You can create as many as connections but only one will be default at a time.

Sep 14, 2015

Installation of oracle database driver in ireport

Following steps are required to install oracle database driver in ireport

1.) Goto Windows Menu bar and click on Services or press Ctrl+5

2.)  Now you will see databases driver listed in service window.

3.) To add database driver right click on Driver folder and click on New Driver.

4.) New window is opened .


5.) Click on Add to browse and select ojdbc6.jar jar file save in system.

     In Driver Class section oracle.jdbc.OracleDriver is selected and name as Oracle Thin.

   Now click Ok to finish Installation.

6.) Now you will see Oracle Thin driver has been installed and showing in Driver List.