BackPrevious Page Next PageNext

Oracle Stored Procedure UDS

Due to the unique nature of Oracle stored procedures, you cannot add them directly into a JReport catalog. As a substitute, JReport has developed the user data source API which can use stored procedures in Oracle. The class is named OracleProcedureUDS, in the package jet.datasource.oracle. The UDS class is already included in JReport Designer and JReport Server; therefore, you do not need to write any Java code or modify the classpath.

To add a stored procedure into a JReport catalog, take the following steps:

  1. Start JReport Designer and open the catalog to which you want to add it.
  2. In the Catalog Manager, right-click the catalog data source the stored procedure is to be added, then select New User Defined Data Source. The New User Defined Data Source dialog appears.

    Add User Defined Data Source dialog

  3. In the Name field, specify a name for the UDS.
  4. In the Class Name field, input the UDS class jet.datasource.oracle.OracleProcedureUDS.
  5. In the Parameter box, enter the parameter as required.
  6. Click OK, and the UDS class will be added into the catalog.

Formats of the parameter string

In the New User Defined Data Source dialog, the format of the parameter string is one of the following types. You can choose one according to your requirements. When the stored procedures used in Oracle have different names, either of the following two formats can be used. However, when the stored procedures used in Oracle have the same names, you can only use the second parameter string. In addition, when you use the second parameter string, the parameter value only contains value. You need to add the data type and index of the parameter value in the user defined data source class.

If you do not want to specify the connection information in the parameter string, you can also write the parameter as follows:

In this case, the default connection defined on the data source, to which the stored procedure UDS is added will be used. Only when the information of the default connection and that of the stored procedure UDS match, can the stored procedure UDS be added successfully. You can change the connection at runtime via datasource.xml, Engine API or Server API in JReport Server.

The following explains the lower-case words in the parameter strings in detail. Substitute them according to your requirements.

Below is an example of the parameter string:

DRIVER=oracle.jdbc.driver.OracleDriver&URL="jdbc:oracle:thin:@dbserver:1521:orcl"&USER=scott&PSWD=tiger&OWNER=SCOTT&PROCNAME=getAuthor&SQL={call getAuthor(?, ?, ?}&REFCURSORINDEX=2&PARAMVALUE=0.5,1999-7-10

If you want to change the connection dynamically, you can define the parameters in this way:

You can change the parameter dynamically to suit your requirements.

Troubleshooting

If you get an "ArrayOutOfBound" error or a "Not all variables are bound" error while importing a stored procedure, you can check the following points:

When you get a NegativeArraySizeException error while running a report designed with a stored procedure, you can check whether some UDS columns return a negative scale (right-click the UDS column, select Properties, and then check Scale). If yes, it means that your original table column called by the stored procedure is likely to be of a Float data type. This returns the wrong Scale for the UDS column. Follow the steps below to modify the UDS column's scale:

  1. Open the Catalog Manager.
  2. Click Options on the toolbar.
  3. In the Options dialog, select Catalog in the Category box, uncheck the option Forbid editing data object properties, and then click OK.
  4. Highlight the UDS column name that you are having the problem with and click Show Properties on the toolbar to show the Properties sheet. Now you can change the property values, such as SQL type, precision, and scale to the correct values. For instance, you can change the negative scale of the problematic column to the correct value.

Notes:

The following are some specific examples of adding Oracle stored procedures UDS to a catalog:

Example 1: Stored Procedures Defined Outside of a Package

Example 2: Stored Procedures Declared and Defined in a Package and Package Body

Example 3: Functions Defined Outside of a Package

Example 4: Functions Declared and Defined in a Package and Package Body

BackPrevious Page Next PageNext