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-12
Writing Data to a File or Terminal
{
...
String outputFileName = "/usr/mydir/spj.output";
FileOutputStream fileStream =
new FileOutputStream(outputFileName);
PrintStream printStream =
new PrintStream(fileStream, true);
...
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