Jump to content
Changes to the Jaspersoft community edition download ×
  • How to execute the Oracle Stored Procedure in jasper report in iReport editor environment


    akonkin
    • Product: iReport Designer

    Steps that should be done before the steps that were described in this article:

    1. Oracle XE database should be installed. You can download and install this database from the oracle site. Installation is fairly easy on Windows, and we did not receive any errors during installation process.
    2. Oracle provides convenient GUI tool to administer databases, create queries and stored procedures. This is a free tool that is called SQLDeveloper and can also be downloaded from the Oracle site.

    Since the previous steps were successfully completed we can start to prepare our test environment.

    The example that is described in this article is based on the sample database (HR) that is supplied with Oracle 11/XE edition.

    The user under which we should work with this database (HR) is locked for security purposes.

    Let's unlock this user. To do this we should connect to Oracle database as SYSTEM user

    connect_to_oracle_as_system_user(1).png.3081cc8a102b95701025c97d65f17616.png

    fill_in_username_and_password(1).png.3064c01a485606bdb37a7c3fcced1af0.png

    unlock_HR_account.png.36473d8a2642859b748bb54e0ead03a4.png

    In Sqldeveloper create new connection with the name 'HR' to HR database that had already been defined and unlocked in Oracle.

    define_new_connection_test_it_and_click_save_button.png.25bd4222a6e5557506136d64bce22afc.png

    Connect to HR database as HR user

    connect_to_HR_database_as_HR_user.png.53dffbe435e692bc5cc1e834594b4797.png

    Create a stored procedure emplist_proc. Beneath I quote the text of this Stored Procedure.

    create or replace procedure emplist_proc(emp_cursor out sys_refcursor) is
        begin 
            open emp_cursor 
            for select first_name,last_name,email 
            from employees 
            where rownum < 10; 
        end; 
    

    Click Run button to create Stored Procedure.

    sample_of_stored_procedure.png.17f09b11582f3413fa9016f740d4b0e2.png

    After the Stored Procedure appeared execute it to check that it works. It should be sucsessfully executed and return the result set of rows.

    sample_of_stored_procedure_compiled_tested.png.a36d8594121b961ba1f7a228184e7c93.png

    At this point we have done all things in Oracle and can start iReport editor.

    Let's create a connection to HR oracle database. To do this we should point the path to Oracle driver

    iReport_point_the_path_to_Oracle_driver(1).png.44b2ac575527762807db048214635808.png

    and configure connection to HR Oracle database

    iReport_define_connection_to_HR_database_and_save_it.png.e0ac1308b5bfb639759cce5d12543bc4.png

    Then we should:

    1. create test report
    2. open Query Editor
    3. select 'plsql' as the Query Language
    4. add the string that should execute the Oracle Stored Procedure: {call emplist_proc($P{ORACLE_REF_CURSOR})}

    To automatically retrieve the fields that should be returned by the Stored Procedure click Read Fields button.

    If you click Read Felds button and receive message "ERROR:SQL Problems:Invalid column type: 2000"

    please create these fields manually according to their description in the HR database.

    iReport_manually_add_fields_in_the_editor.png.ed99ed1c8af437e83acdffb2054b545c.png

    iReport_manually_add_fields_in_the_editor_1.png.2bceda0b30a5857a56a4ceff533c4102.png

    sp_works_with_connection_prefix_pic_2(1).png.625d3b2e392143489672dd5871a7067c.png

    At that point we can try to execute the report and test the Oracle Stored Procedure by clicking Preview button.

    sp_works_with_connection_prefix_pic_3.png.c0a728f4fb0cb149cbbc923091b643fd.png

    As we see on last screenshot the report that was based on the Oracle Stored Procedure was successfully executed.

    Thats all. Thank you for reviewing my article :)


    If you are planning on deploying report which is calling stored procedure to a web application environment - please read following article:

    How to execute the Oracle Stored Procedure in jasper report in Web Application environment

    or

    Calling Oracle Stored Procedures from JasperReports Server

    It will save you trouble in stepping on common pitfalls.

    connect_to_oracle_as_system_user(1).png.fa5f918776aeb39842c0be94489fef8f.png

    fill_in_username_and_password(1).png.dfda892fbe5a47f83e6cf96c5091b8a1.png

    unlock_HR_account.png.92c894a08fe1a17401c05328e7ae59e5.png

    define_new_connection_test_it_and_click_save_button.png.19c2714da84143d2067bd7f10105333a.png

    connect_to_HR_database_as_HR_user.png.529103e583a7f605ddeb35b86f19d9b2.png

    sample_of_stored_procedure.png.95292d08fbbc8702a4b938bea373dc43.png

    sample_of_stored_procedure_compiled_tested.png.8fddb1af0ff949d46f9bd862514e96ae.png

    iReport_point_the_path_to_Oracle_driver(1).png.4e5317c76a099f547ab82650b924c3a5.png

    iReport_define_connection_to_HR_database_and_save_it.png.69d604c22567a4012d91c653c5a588b3.png

    iReport_manually_add_fields_in_the_editor.png.3c5fb3f7a7164b6cf12fbee18ad2ebe2.png

    iReport_manually_add_fields_in_the_editor_1.png.4d040032c6404dcd2eb5d79b2089a975.png

    sp_works_with_connection_prefix_pic_2(1).png.24cf11aa2a28c50bf2eb4fc21e4ea4b0.png

    sp_works_with_connection_prefix_pic_3.png.aecf1c2475262df67b4ab2305a441101.png


    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...