SQL/MX 3.2 Guide to Stored Procedures in Java (H06.25+, J06.14+)
Writing SPJ Methods
HP NonStop SQL/MX Release 3.2 Guide to Stored Procedures in Java—691166-001
3-12
Writing Data to a File or Terminal
Writing Data to a File or Terminal
Within the SPJ environment, data sent to the System.out and System.err output
streams goes nowhere by default because the SQL/MX UDR server runs without a
terminal. You can add code to your SPJ methods to write data or debugging
information to an OSS file. You can also map one or both of the System.out and
System.err streams to a file.
Because terminal devices have OSS path names, you can route output from an SPJ
method to a terminal device if you know the OSS name of that device. The tty
command in OSS writes the full path name of your terminal device to standard output.
This example enables an SPJ method to write a message into a file:
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);
...
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);
...










