iReport (Jasper Report) Related Information

To Set the ORACLE Driver to Connect the ORACLE database:
#Tools->Options->Classpath->Add JAR->Show the path of ORACLE Driver (Ojdbc14.jar).

To Get database Connection :


1) click "Connections / Datasources"  icon in toolbar(Report datasources)

2) click "New" and set up a "Database JDBC Connection" using driver from step 2
3) click "Test" to verify the data source works correctly
4) click "Save" to save the data source


To Create New Report:

1)File=>New..=>Select Blank A4 and Press “Open this Template” Button=>Set ‘Report Name,Location,File’=>Next=>Finish.
2) Select the Report and click on mouse Right button =>Edit Query=>
              a) Select expected query language, b) Write query in the text area. c) Ok
3) Click on right button by selecting the report and click on compile Report.

To add Serial No in Report 1st Column:
1. Just Drag and drop “REPORT_COUNT” variables to Details Band , save it  and see
or,
1. Take a Text Field (Dragging from the palette to the report 1st Column).
2. Right Click on The Text Field and click on “Edit Expression”.
3. Paste “$V{REPORT_COUNT}” upon “$F{field}”.
4. Click on Apply Button.

To show sum of a Column’s all value in the footer of a column Or, For Grand total of a column :
  1. Right click on “Variables” and click on “add variable”.
  2. Select it and from the properties panel (You will get in the right side for  iReport version 5.00) Change the following things-
Name => As you wish
Variable Class => java.lang.Integer/ Bigdecimal(according to the field data type which want to sum)
Calculation=>Sum
Reset type=>Report
Variable Expression=> Write The Column which you want to sum in that way. i.e.-$F{Column name}
  1. Click on Save Button (Upper Right Corner of iReport)
  2. Drag and drop it in Column Footer
  3. Save it and See…
To show sum of two or more Column’s value in another column Or, For sum two or more column value :
  1. Right click on “Variables” and click on “add variable”.
  2. Select it and from the properties panel (You will get in the right side for  iReport version 5.00) Change the following things-
Name => As you wish
Variable Class => java.lang.Integer/ Bigdecimal(according to the field data type which want to sum)
Calculation=>Nothing
Reset type=>Report
Variable Expression=>Write The Columns  which you want  to sum  in that way
i.e.-$F{Column1 name}+$F{Column2 name}  Or , the better way is as follows-
new BigDecimal
(
$F{Column1 name}==null ?0.00 : $F{Column1 name}+
$F{Column2 name}==null ?0.00 : $F{Column2 name}
)
  1. Click on Save Button (Upper Right Corner of iReport)
  2. Drag and drop it in the Details Band right place where you want to see
  3. Save it and See…
To see a Sub Report in a Report: 
There are many way to use Subreport in a master report. I think it will be better to master report and subreport separately at first. Then do the following steps one after another -
1.       Just drag and drop “Subreport” from “Palette” to the report where you want to see the subreport.
2.       Then you will see a interface here Select “Use an existing report” and Browse the .jrxml file that you made as your subreport  and Click on Next > button
3.       Select “Use the same connection used to fill the master report” and Click on Next >  button
4.       Click on Next> button again
5.       Select “Store the directory name in a parameter” $P {SUBREPORT_DIR} + "x_subreport1.jasper" and Click on Finish button.
6.       If you use any used any Parameters or Variables to run the subreport then you have to create the same (type and Name) Parameters or Variables in master report also. It will be better to create Parameters or Variables in same type and name otherwise you need to do some extra task.
7.       Now select  the subreport  and from the Properties panel change the following -
Subreport Exoression : ” $P {SUBREPORT_DIR} + "x_subreport1.jasper" to ” $P {SUBREPORT_DIR} + "\\x_subreport1.jasper"  use “\\” to forward slash .
Parameters :  click on “Copy From Master” button and ok
8.       Save it and See…  


To get subreport specific value into main report:
  1. In  Sub Report  do the followings -
    a) Create a variable
    b) Change the variables “Properties “ panel’s following things-
    Name:  Anything you wish
    Variable Class : Any type you need to have
    Calculation: System
    Report Type: Report
    Increment Group : None
    Initial Value Expression : $F{column_name}(the field value you want to have in main report )
  2. In  Main Report  do the followings -
    a) Create a variable
    b) Change the variables “Properties “ panel’s following things-
    Name:  Anything you wish(it is better give the same name of subreport  variable)
    Variable Class : Any type you need to have (it is better give the same type of subreport  variable)
    Calculation: System
    Report Type: Report
    Increment Group : None
  3. Select Sub report and change the Properties Panel’s following field -
    Return Values – click on “add” button change the following things-
       Sub report variable =>Write same name as sub report variable
       Local destination variable =>Select the subreport variable you want to see
  4. click on “Ok”=> Click on “Ok” again
  5. Drag and drop the variable (which is created in main report for sub report specific field or variable value )in the main report
  6. Save and click on preview to see…
# An example of a ternary operator- “new Integer($F{NB}.intValue()+$F{VAT}.intValue()+$F{CMLPC}.intValue()+$F{MRENT}.intValue())>200?"1":"" ”
# An example of a Sum of  different column value-(new BigDecimal($F{NB}.intValue()+$F{VAT}.intValue()+$F{CMLPC}.intValue()+$F{MRENT}.intValue())).toString()

4 comments:

  1. Hi mohammed,

    How could i create a jasper report using a PoJO class and an action class??? by using Struts frameworks.

    ReplyDelete
  2. See the Link Page u can get ur solution

    http://marufurrashid.wordpress.com/category/ireport-jasper-report/

    ReplyDelete
  3. Hello Kazi,
    We have developed new gen developer friendly BI framework with some extremely unique features. Would like to give u early access & love to hear your opinion. Please do let me know of how to reach out to you. Would be launching product in 4 weeks from now. Also can you share your email-id so that we can more details about the product or you can send us the test mail.

    ReplyDelete