Oracle stored procedure UDS

Due to the unique nature of Oracle stored procedures, you cannot add them directly into a JReport catalog. In this sense, the usage of JReport Designer is limited when you use an Oracle database. 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.

To add a stored procedure into a JReport catalog:

  1. Start JReport Designer and open the catalog to which you want to add it.
  2. In the Catalog Browser, right-click the catalog data source the stored procedure is to be added, then select Add User Defined Data Source.
  3. In the Name field of the Add User Defined Data Source dialog, 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 Add User Defined Data Source dialog, the format of the parameter string is in either of the following. You can choose one according to your requirement. 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.

Substitute the words in lower case according to your requirements.

Where:

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:

oracle.jdbc.driver.OracleDriver=@driver, jdbc:oracle:thin:@dbserver:1521:orcl=@url, scott=@user,

The parameter string will then be either of the following:

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 below 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 Browser and click the Options button on the toolbar.
  2. In the Category box of the Options dialog, select Catalog, uncheck the option Forbid editing data object properties, and then click the OK button.
  3. Highlight the UDS column name that you are having the problem with and click the Expand button 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: