SQL/MX Guide to Stored Procedures in Java (G06.24+, H06.03+)

Writing SPJ Methods
HP NonStop SQL/MX Guide to Stored Procedures in Java523727-004
3-5
Static Java Variables
This Java method also uses a Java wrapper class in its signature to anticipate a
possible returned null value:
public static void employeeJob(int empNum,
Integer[] jobCode)
Static Java Variables
To ensure that your SPJ method is portable, you should avoid declaring static variables
in the method. NonStop SQL/MX does not ensure the scope and persistence of static
Java variables.
Consider these drawbacks to using static variables in your SPJ method:
If an SQL/MX UDR server crashes, the calling application receives a new SQL/MX
UDR server and a new SPJ environment, including new copies of all static
variables initialized in that server. For more information, see SQL/MX UDR Server
Process on page 1-12.
When application classes contain static variables, NonStop SQL/MX does not
ensure that exactly one copy of those static variables is in a given SQL/MX UDR
server process or SPJ environment. For more information, see Class Loaders in an
SPJ Environment on page 1-15.
Nested Java Method Invocations
An SPJ that invokes another SPJ by issuing a CALL statement causes an additional
SQL/MX UDR server process to be created. Nesting SQL/MX UDR server processes
in this way wastes resources and diminishes performance. If you want an SPJ method
to call another SPJ method, invoke the other Java method directly through Java
instead of using a CALL statement.
Accessing SQL/MP and SQL/MX Databases
SPJ methods that access an SQL/MP or SQL/MX database must be from either a Java
class that uses JDBC/MX method calls or an SQLJ program (embedded SQL in Java).
Use of java.sql.Connection Objects on page 3-5
JDBC/MX-Based Java Method on page 3-6
SQLJ-Based Java Method on page 3-7
Referring to Database Objects in an SPJ Method on page 3-8
Exception Handling on page 3-10
Use of java.sql.Connection Objects
Typically, the default connection in an SPJ execution environment has a data source
URL of "jdbc:default:connection". However, NonStop SQL/MX does not
support a default connection in the SPJ environment. In NonStop SQL/MX, SPJ
methods that create java.sql.Connection objects are not portable to other