Refactoring method code for creating Java stored procedures

Before you can create a Java™ stored procedure from a method, you must refactor the code in the method so that it can be invoked as a stored procedure.

About this task

The method from which you want to create the Java stored procedure must be a valid entry point for the stored procedure. Specifically, the method must meet the following requirements:
  • The method must be defined as a public static void method
  • The database connection in the method must be defined as jdbc:default:connection.
  • Any data returned by the method must be returned in a single-element array.
  • If the method handles checked exceptions, the exceptions should not be resolved in the method. Exceptions must be passed back to the invoker through a throws clause.
If you are working with a pureQuery-enabled Java project, you must meet additional refactoring requirements. See the sample code for the following cases:
  • Returning a result set from a method in a pureQuery application that uses inline methods
  • Returning an OUT parameter from a method in a pureQuery application that uses annotated methods
  • Returning a param from a method, based on a pureQuery application that uses annotated methods and runs SQL statements dynamically
Tip: Meeting all of the requirements for the Java stored procedure entry point might require significant changes to the method code. Instead of refactoring the code of the actual method, consider creating a copy of the method and using it as the stored procedure entry point.

To refactor the method code:

Procedure

  1. Optional: Create a copy of the method to use as the Java stored procedure entry point.
  2. For the method that you choose to use as the Java stored procedure entry point, define it as public static void.
  3. Define the database connection in the method as jdbc:default:connection.
  4. If the method returns data, define a single-element array for returning the data.
  5. If the method handles checked exceptions, define a throws clause in the method signature and pass back the exception data through this clause.

Example

The following topics show examples of how to refactor methods in pureQuery code:

Feedback