SQL/MX 3.2.1 Guide to Stored Procedures in Java (H06.26+, J06.15+)
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 (page 25).
• 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 (page 28) .
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 a Java class that uses
JDBC/MX method calls.
• Use of java.sql.Connection Objects (page 53)
• JDBC/MX-Based Java Method (page 54)
• Referring to Database Objects in an SPJ Method (page 55)
• Exception Handling (page 56)
Use of java.sql.Connection Objects
NonStop SQL/MX supports a default connection in an SPJ execution environment, which has a
data source URL of "jdbc:default:connection". For example:
Connection conn = DriverManager.getConnection("jdbc:default:connection");
java.sql.Connection objects that use the "jdbc:default:connection" URL are portable
to the NonStop SQL/MX platform from other database management systems (DBMSs).
NonStop SQL/MX controls default connections in the SPJ environment and closes default connections
when they are no longer needed. Therefore, you do not need to use the close() method in an
SPJ method to explicitly close a default connection when the connection is no longer needed. In
fact, if an SPJ method returns result sets, you should not explicitly close the default connection.
NonStop SQL/MX closes the connection used to return result sets after it finishes processing the
result sets. If an SPJ method closes the connection on which the result sets are being returned, those
result sets will be lost, and the calling application will not be able to process them.
A default connection that is acquired when an SPJ method executes is not guaranteed to remain
open for future invocations of the SPJ method. Therefore, do not store default connections in static
variables for future use.
The default connection URL, "jdbc:default:connection", is invalid outside a DBMS, such
as when you execute a Java method in an application. To write an SPJ method that operates in a
DBMS, in an application, or both, without having to change and recompile the code, use the
sqlj.defaultconnection system property:
String s = System.property("sqlj.defaultconnection");
if (s == null) {
s = other-url;
}
Connection c = DriverManager.getConnection(s);
The value of sqlj.defaultconnection is "jdbc:default:connection" in a DBMS and
null outside a DBMS.
Accessing SQL/MP and SQL/MX Databases 53










