Jump to content
JasperReports Library 7.0 is now available ×
  • Definitive guide for creating reports. Creation of sub reports. Calling of stored procedure. Step of parameters. (Guía definitiva para la creación de reportes. Creación de Sub Reportes. Call Stored Procedure. Paso de los parámetros)


    tsrock666

    JasperReport version 6.3.1

    Java 1.8

    intellij Idea 14

    Maven 3.2.3

    Ireport 5.6

    I have been creating a report that met certain aspects in the execution. This report requires calling segments of PL codes looking for insurance quote information. For this work it was necessary to make calls to different stored procedures that return the data. I searched for many examples, but none provided effective or complete information for what I was looking for, so I started to create my own code. It was not easy but after 4 days of tests and frustrations here they are the results.

    • First of all, start by opening Ireport. I used the latest version available 5.6. Open a new report. An important point when creating the reports is consider that iReport uses the "Groovy" language by default. Edit the xml code of the report and remove the "Language = Groovy" attribute that the report has setted. This will give you problems later. Among the properties of the iReport there is the possibility of setting the java language by default. But it is important to check on each occasion to create a new report.
    • Set the "classpath" tab in the oracle driver to use. I set ojdbc6.jar (It's undifferent the version). 

    5ctOKbs.jpeg.fe0ba8c03ca71e28535e583133bfb134.jpeg

    • Then, create a database JDBC conecction. This case it's a oracle data base.

    3Ba0p30.jpeg.3b1790c17812d8e71f8ed1b28906236f.jpeg

    • Once the connection is established and tested. Go to your database administrator and proceed to create the Stored Procedure.

    souxIFf.jpeg.9e2ef50311cdf188671db394218e6714.jpeg

     

    • I created a Stored Procedure that receives two parameters, a first parameter called codcli (the example was designed in Spanish) that I will use later to pass a value. The other parameter is of type sys_refcursor, which uses the report to access the created stored procedure. Go back to Ireport. Given that you already created your Stored Procedure, you know well the fields that your code returns. Create as many fields in iReport as you return the select statement. I have three fields, NOMBRE, CODIGO, EMAIL. If you wish, you can put them in the created report.
    bC5SzOw.jpeg.d15cf8195e1da7d8d027439debbe33a2.jpeg
     
    • A very important point. Create a parameter called ORACLE_REF_CURSOR (or you prefer to call it). This parameter must be of type java.sql.ResultSet. You can set it in the "Parameter Class" attribute in the creation of the attribute. Also create the other parameter (if your code requires it) to be used later from the class to pass a value that will use the stored procedure to search the data.

    msIJk19.jpeg.96b689b5c68dcb4be9b792aa793b7ffd.jpeg

    • Next step, create set call to stored procedure. Find the option to create "reports query". There, you will write the call to the stored procedure, setting the required fields as parameter (the ORACLE_REF_CURSOR parameter is mandatory). Set "query lenguage" as "p/sql. If you are going to use the other paramentro, it is important to mention that you should put a "!" So that there are no problems in the invocation from the class. Ex: $ P! {Codec}. You'd could see an error "ERROR: SQL Problems: Invalid column type: 2000", this is almost normal in new versions of iReport. Click the "read fields" button. You should be able to see the fields that are returned in the Select statement of the stored procedure. The "Refresh Preview Data" button should display the results.
    • Save and compile your report. Maybe I could read some warning (which should not) but it may go unnoticed. In the "Preview" button of iReport, the report can be generated. If you have problems, if you do not see the data. Try regenerating the fields. Delete the fields that I created previously and write them again (when you set the call in "report query" the "Read Fields" button creates them again). But up to this point there should be no problems.

    1tdCyAG.jpeg.eed591e90cbc4da187f91347ca1c9f58.jpeg

     

    • In the end your first report should look very similar to this. This will be the report that will be used as the sub report of a principal.

    qE8V84n.jpeg.3d2891a5e315be33ce8b27c25ea24522.jpeg

    Very well, if you only need to run the report in an external and individual way, you can get here, but if you are developing a program or a web application as in my case, keep moving forward. Here's how to make the report run from a java program for a web application:

    • You must create a new report, which one will be used as the main report from where the sub reports necessary will be created to invoke the other reports you have created already. Create a sub report and put it in the "detail" band of the report. If you later need to use several sub reports, you must create group bands for this job.

    zjdqN38.jpeg.fbe4b3d3986c9b3a9c50dfbc8866b223.jpeg

     

     

    5ctOKbs.jpeg.dcde25ed5ea2218f72499afc254b1f7e.jpeg

    3Ba0p30.jpeg.afc9218a184b4d6001efc1c9d033ea0e.jpeg

    bC5SzOw.jpeg.dceeeef002d53c3973b98311ab071fcf.jpeg

    msIJk19.jpeg.ff030090668d7b96e9a62c27f6884d73.jpeg

    1tdCyAG.jpeg.be6f61b9d13017cccc39b2c78536f3ad.jpeg


    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...