SQL/MX 3.2.1 Guide to Stored Procedures in Java (H06.26+, J06.15+)
...
printStream.println("The salary was updated for employee "
+ empnum);
...
}
Suppose that an employee number of 202 is passed to the SPJ. When a CALL statement invokes
this SPJ method, the text "The salary was updated for employee 202" is written to the
file /usr/mydir/spj.output.
You can also redirect one or both System streams to an output stream of your choice. This example
extends the code from the previous example for stream redirection:
public static void adjustSalary(BigDecimal empNum,
double percent,
BigDecimal[] newSalary)
throws SQLException
{
...
String outputFileName = "/usr/mydir/spj.output";
FileOutputStream fileStream =
new FileOutputStream(outputFileName);
PrintStream printStream =
new PrintStream(fileStream, true);
System.setOut(printStream);
System.setErr(printStream);
...
// This message goes to the output stream.
System.out.println("The salary was updated for employee "
+ empnum);
// This message goes to the error stream.
System.err.println("The salary was not updated for employee "
+ empnum);
...
}
When a CALL statement invokes the SPJ method, a message is written to the file
/usr/mydir/spj.output. If the invocation succeeds, this message is written to the file:
The salary was updated for employee 202
If the invocation fails, this message is written to the file:
The salary was not updated for employee 202
Compiling Java Classes
Before registering a Java method as an SPJ, you must compile your Java source file into Java
bytecode by using the Java programming language compiler (javac). To compile a class file, see
the NonStop Server for Java Programmer's Reference or the NonStop Server for Java Tools Reference
Pages.
58 Writing SPJ Methods










