Pages

Showing posts with label jasperreport. Show all posts
Showing posts with label jasperreport. Show all posts

Thursday, March 7, 2013

weblogic error: package net.sf.jasperreports.engine does not exist

I just recently come across while deploying sample report application on weblogic. and it was giving me error for all of jasper report classes not found in stack trace.
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: C:\MW_WL12C_Domains\test\report32name_1362666859233_104255.java:4: error: package net.sf.jasperreports.engine does not exist import net.sf.jasperreports.engine.*; ^ C:\MW_WL12C_Domains\test\report32name_1362666859233_104255.java:5: error: package net.sf.jasperreports.engine.fill does not exist import net.sf.jasperreports.engine.fill.*;
I thought of why even after giving all jar files in web-inf/lib folder it did not work? after searching i found that if you tried to compile report from jrxml to jasper in your web application  it needs jdt compiler jar which was missing along with other jar. so for any report to compile and run it need all following jar and importantly to remove above errors you need jdt-compiler.jar
commonly all required jars are as below
commons-beanutils-x.x.jar, commons-collections-x.x.jar, commons-digester-x.x.jar, commons-logging-x.x.x.jar, commons-logging-api-x.x.x.jar, itext-x.x.x.jar, jdt-compiler-x.x.x.jar
more additional jars if you have database connection, chart, images etc.

Tuesday, December 6, 2011

working with jasperreports.properties

jasperreports gives us numerous properties settings that we can customize at design or compile time and
modify/control the execution of reports.

Jasperreports has his own default settings and it reads it from its jar file jasperreports-x.x.x.jar with the file name default.jasperreports.properties, unless you specify differently. Property file gives us flexibility of changing its execution behavior at run time, it may get applied to all report or to specific report as well, all depend upon how you specify properties.
Following are the ways you can define the properties which will be read by jasper and work accordingly.

1. specify in system properties.
    if we want to load some specific properties then we can specify it system.setProperties(k,v) format and compiler will override it with default. used for global changes for all reports.
   
2. specify in jasperreports.properties file   
    create your own jasperreports.properties file (normally override default by copy and modify ) and place it in classpath so that compiler will override default properties. this will get applied to all reports getting compiled/executed so useful for global changes.
   
3. specify properties in template file.
    if you want to specify only for specific report and not for others there is way to specify properties at top of your report template so that those will be overridden by compiler with default properties. You can specify properties in template as below
   
   
there are few properties specifically for export can be set through exportmanager you use at time of exporting programmatically as exportmanager.setParameter(k,v) for example

property file has
net.sf.jasperreports.export.xls.one.page.per.sheet=false

same can be set at run-time programmatically in code using xlsExporter as below

xlsExporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);






hope this helps you.
Lastly, If possible before closing, click on ad to support me.

Wednesday, October 5, 2011

Calling Oracle Stored Procedure in JasperReports

In my previous article I have very briefly explained how  PLSQL has been supported in jasperreports. But it is not that easy when it comes to different databases. Here I will present how we can call stored procedure from jasperreports. For this sample I have used iReport  4.1.2 designer and Oracle database, it is supported in previous versions as well, may be with minor changes.
Well to begin with we need to create a procedure. That returns cursor. Here I am using a simple procedure with sample database available in oracle (HR).

Employee table


Procedure



Now follow steps to implement stored procedure in jasper report. 
Create a new blank report.
1.  Add PLSQL executer to jasperreports.properties. 
Select Menu Tools>>options>>query Executers 
Find that below entry is added in the properties, if you are using latest version it will be already there for older version you need to add it separately. Please note that for this you need a jar jasperreports-extensions-3.5.3.jar which will be available in 4.1.2 version.
Language =plsql
Factory Class =com.jaspersoft.jrx.query.PlSqlQueryExecuterFactory
Fields Provider Class =com.jaspersoft.ireport.designer.data.fieldsproviders.SQLFieldsProvider

    2.  Also go to classpath tab and make sure you added classess12/14/ojdbc.jar in classpath  

    3.  Make sure that you have created oracle datasource connection available.
    4.  Open  report Query , select Query Language = “plsql”  

    5.  Write your plsql query as below make sure you have  procedure call withing  curly braces “{}“
    {call emplist_proc($P{ORACLE_REF_CURSOR} ) }
    If you have your procedure accepting more input parameters you can have them passed as parameters.
    6.  If you notice that parameter “ORACLE_REF_CURSOR” is available in Available Parameter list we need to pass it as our OUT parameter for the stored procedure which will return cursor.  Also note that if you are using old versions you can create your own parameter name “cursor” with datatype as “java.sql.ResultSet”  and also make sure “use for prompt” is not selected.
    7.  Read fields may not work in some cases but its ok. You can manually add them if do not work.
    8.  Place the fields and you are done !. 

    9.  Click on preview and you will see that your report is generated.

















    10. lastly, if possible before closing, click on add to support me. Thanks

      Monday, November 1, 2010

      Procedure / plsql support in jasper report

      I am not very sure from which version Jasper started supporting this feature, but recently when I was evaluating 3.7.5 version I suddenly explored this... and it is so easy...!

      Well here it is how...  when you write a query in the querystring tag, Jasper has added a property called "language" and here it supports for different languages querystring. so for calling a procedure from jasper report you need to set this attribute value as "plsql", and done! just call your procedure from querystring.

      <queryString language="plsql">
           <![CDATA[call myproc()]]>
      </queryString>
      








      just to make sure that your jasperreport version support this feature check your xml schema or jasper that it has this property, I am quite sure that when jasper was having DTD as validate jrxml, that time it was not supported.

      Wednesday, October 13, 2010

      creating a crosstab report with jasper report

      creating a crosstab report with jasper is became very easy task now...
      as I explore it I found it very easy and simple to do...
      the most tedious task was earlier to manage with the query to get the data in cross format. since there was no alternate or easy feature available from database either.
      but for now with japserreport it become so easy that you don't have to modify your query at all just fire simple query and its done.
      lets see how.

      to show example I will use hssqldb that shipped with ireport tool.

      concept: in a business case we have some times a requirement where we need a crosstab data for analysis which is difficult to achieve. because what we store in database is in number of rows and if we need that to be shown in columns is very difficult to achieve.

      in our example lets see following result of table "tasks"

      and assume now that we have a requirement to show this data in a different format as
      group scheduled and actual and subgroup with tasks within and show them as columns
      and subtasks as rows. that means it will look like something like this

                      actual                           | scheduled
                     task1 | task2 | task3      |task1 | task2 | task3     
       subtask1 
      subtask2
      subtask3
      etc.

      lets see how we can put this in cross tab report as below.
      1. open ireport
      2. file>>new>>launch report wizard (click) button
      3. give reportname.>> next>>
      4. select database connection>>add sql query as "select * from tasks" >> next>>
      5. select all fields >> next>>
      6. next>> finish>>
      7. set all bands height as 0 except summery band.

      8.   drag and drop crosstab icon on summery band.
      9.   select "main report databaset" >> next
      10. in rows we want to show subtasks so select "subtask Field" in rowgroup1 , group by "unique" >> next>>
      11. now for column we have two level of grouping first is actual and scheduled and under it tasks so for
      columngroup1 select "series Field" group by "unique">>
      columngroup2 select "task   Field" group by "unique">> next>>
      12. for data we will select "percent Field" , function "nothing" because we want to show values as it is.>> next>>
      13. you can choose colour scheme of your choice and also column/row grouping if you want for my example i am leaving it unchecked that means I am not using row& column grouping.
       >> finish.

      Thats all your report is done now click on preview and try to see how it looks.

      after genrating view see it as below.


       


      Tuesday, October 12, 2010

      creating jasper sub-report using iReport

      creating a sub-report example with Jasper

      Pre-requisite: I assume that you know how to create normal reports using iReport GUI tool also basic knowledge of database, sql with MySql.

      before we start with actual creating of report lets understand the database that we require.
      following is the table structure that we require.

      I have taken the sample database that comes with iReport hsqldb, you can use that directly also.










      following is that data within each table.

      I have restricted data to minimum to show here if you fire the same query in iReport you can see all data.














      so basically it shows the billing information for each transaction taken place, master table is document and its detail table is positions.

      lets now create a sub report first which we need to include in the main report for every transaction.
      so open iReport tool
      1. file>> new... click on "Launch Report Wizard"

      2. enter report name and its location where it will save report on local machine
      name: sub-rpt-det
      location: C:\data\mytest
      file: C:\data\mytest\sub-rpt-det.jrxml

      click on next,

      3. if you are using hsqldb / mysql databse as a datasouce choose appropriately.
      paste following query in the tab
      select * from positions
      where documentid=0
      order by positionno
      later, we will be replacing the documentid value with the actual parameter passed from the master report.
      click next>>

      4. select all fields shown in the left side of fields combo
      click next>> next >> finish

      5. set title, page header, summery band height as 0 (zero)

      6. add the fields to report detail section

      7. add fields column labels in the column header

      8 now goto report inspector >> expand variables >> right click on variables>> select "Add Variable"
      9. check the following variable1 properties for the variable that just created. modify them appropriately














      10. similarly create another variable named tot check out its properties as below














      11. Place the field "cost" in detail section at end and "tot" field in column footer along with label (see below)

      12. add a "Rectangle" box in the column header and move it to back, add a background color as gray

      13. add a "line" the column footer.

      your report will look like as below





      14. try to click on preview button and check if its generating output

      15. go to report inspector>> expand parameters>> right click >> "Add Parameter"
      add a parameter named "m_docid" change its parameter class as "Integer"

      16. click on db tool button is next to preview button
      replace the query parameter from (zero) 0 to $P{m_docid} so your query will look like as below

      select * from positions
      where documentid=$P{m_docid}
      order by positionno
      
      with this your sub report is complete now lets create a master report.

      1. file>> new...

      2. click on button "Launch Report Wizard"

      3. enter report name as "mst_rpt"
      name: mst_rpt
      location: C:\data\mytest
      file: C:\data\mytest\mst_rpt.jrxml

      click on next,

      4. if you are using hsqldb / mysql databse as a datasouce choose appropriately.
      paste following query in the tab
      select d.*, a.* from document d
      left join address a on a.id= d.addressid
      order by task
      click next>>

      5. select all fields shown in the left side of fields combo
      click next>> next >> finish

      6. select Palette>> report element>> sub report
      drag it to the detail section. subreport wizard will appear on screen

      a. select option use existing report and browse and select the sub report that we had created.
      C:\data\mytest\sub-rpt-det.jrxml
      click next>>

      b. select first option "use the same connection used to fill the master report"
      click next>>

      c. it will show paramters created in sub report "m_docid" which we need to map with the master report field so we will be passing our document table's id filed here, click on expression drop down combo you will find all parameters, fields and variables that are defined in master report. choose "id" field from it.
      click next>>

      d. select the first option of subreport expression as "store the directory name in a parameter"
      click FINISH

      so your master report created with its sub report and other fields added in the details band will be seen as below










      click on subreport and check its properties as below












      note the parameters says that one parameter defined click on its button and see that it should show the m_docid as the parameter that we are passing to sub report.

      here is the way to pass parameters to sub-report and to get value from sub-report
      note that when you pass any value to sub report, that value may be parameter/field/variable defined in main report. you have to take special care for variable field of main report that it should have defined and has some value. please see below image how to pass
      define one parameter in sub-report that will accept value from main report.
      make sure that data type of sub-report parameter and main report parameter/field/variable should be same/compatible. here I have defined m_docid which will take value from main report.


      similarly now when you have to define a variable that returns a value from sub report note that
      1. values should come from sub-report variables, and place holder in main report also should be a variable.
      2. variable defined in main report will get populated only after sub-report is totally generated, so it has to be placed after sub report defined.
      please have a look how to get value from sub report.
      1. I have defined "AValueFromSubRep" variable in main report
      2. then I am mapping this variable to the sub report variable "totcost"


      see how its get written in jrxml as below.
      <subreport>
          <reportelement height="34" width="555" x="0" y="43">
          <subreportparameter name="m_docid">
           <subreportparameterexpression></subreportparameterexpression>
          </subreportparameter>
          <connectionexpression></connectionexpression>
          <returnvalue subreportvariable="totcost" tovariable="AValueFromSubRep">
          <subreportexpression class="java.lang.String"></subreportexpression>
         </returnvalue></reportelement>
      </subreport>
      

      now save the report and click on preview it will show the report with its sub report details as below
























      thats how you will do a subreport.


      Lastly, If possible before closing, click on ad to support me.