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-10
Exception Handling
"FROM orders " +
"WHERE order_date = ?");
getNumOrders.setDate(1, date);
ResultSet rs = getNumOrders.executeQuery();
rs.next();
numOrders[0] = rs.getInt(1);
rs.close();
conn.close();
}
Be aware that overriding the default values by using getConnection() or
UDR_JAVA_OPTIONS requires you to hard-code the catalog and schema values and
might make SPJ methods less portable across systems.
Exception Handling
For SPJ methods that access an SQL/MP or SQL/MX database, no special code is
necessary for handling exceptions. If an SQL operation fails inside the SPJ, the error
message associated with the failure is returned to the application that issues the CALL
statement.
Accessing Enscribe Databases
An SPJ method can access and operate on an Enscribe database if you code the
method to use the Enscribe API for Java. For information about using the Enscribe API
for Java, see the JToolkit for NonStop Servers Programmer's Reference.
Using Native Methods
If you want an SPJ method to invoke a native C or C++ method, use the Java Native
Interface (JNI). The JNI enables the Java code in an SPJ method to access a C or C++
library. For information about using the JNI, see the NonStop Server for Java
Programmer's Reference.
Before calling an SPJ that invokes native methods, use the mxudrlink script to relink
the SQL/MX UDR server to the JNI objects. mxudrlink does not support JNI objects
in archive (.a) files. For more information, see Step 5 in Relinking the SQL/MX UDR
Server on Systems Running G-Series RVUs on page 2-5.
Handling Java Exceptions
If an SPJ method returns an uncaught Java exception or an uncaught chain of
java.sql.SQLException objects, NonStop SQL/MX converts each Java exception
object into an SQL/MX error condition, and the CALL statement fails. Each SQL/MX
error condition contains the message text associated with one Java exception object.
If an SPJ method catches and handles exceptions itself, those exceptions do not affect
SQL/MX processing.