SQL/MX 3.2.1 Guide to Stored Procedures in Java (H06.26+, J06.15+)

3 Writing SPJ Methods
Before you can create an SPJ in NonStop SQL/MX, you must write and compile the Java method
to be used as the body of the SPJ. The Java methods that you use for the body of an SPJ are called
SPJ methods.
This section requires a familiarity with writing and compiling Java programs and covers these
topics:
Guidelines for Writing SPJ Methods (page 49)
Accessing SQL/MP and SQL/MX Databases (page 53)
Handling Java Exceptions (page 57)
Writing Data to a File or Terminal (page 57)
Compiling Java Classes (page 58)
Guidelines for Writing SPJ Methods
Follow these guidelines when you write SPJ methods to be used as SPJs in NonStop SQL/MX:
Signature of the Java Method (page 49)
Returning Output Values From the Java Method (page 50)
Using the main() Method (page 52)
Null Input and Output (page 52)
Static Java Variables (page 52)
Nested Java Method Invocations (page 53)
Signature of the Java Method
A Java method that you use as an SPJ must have this general signature:
public static void myMethodName ( java-parameter-list)
Public Access and Static Modifiers
The Java method must be defined as public and static. If a method is private or protected,
NonStop SQL/MX is unable to find the Java method specified by the CREATE PROCEDURE statement
and returns an error. The Java method must be defined as static so that the method can be
invoked without having to instantiate its class.
Void Return Type
The return type of the Java method must be void. The method must not return a value directly to
the caller.
Java Parameters
The parameter types in the Java signature must correspond to the SQL parameters of the stored
procedure that you are planning to create. For type mappings, Table 2.
Table 2 Mapping of Java Data Types to SQL/MX Data Types
Maps to SQL/MX Data Type...Java D ata Type
CHAR[ACTER]CHAR[ACTER]
VARYINGVARCHARPIC[TURE] XNCHAR NCHAR
java.lang.String
Guidelines for Writing SPJ Methods 49