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-7
SQLJ-Based Java Method
rs.close();
conn.close();
}
}
You do not have to explicitly load the JDBC/MX driver before establishing a connection
to the database. The SQL/MX UDR server automatically loads the JDBC/MX driver
when the SPJ is called.
To register this method as an SPJ in NonStop SQL/MX, use a CREATE PROCEDURE
statement. For details, see Section 4, Registering SPJs in NonStop SQL/MX.
For other examples of JDBC/MX-based SPJs, see Appendix A, Sample SPJs.
For information about JDBC/MX, see the JDBC Driver for SQL/MX Programmer’s
Reference.
SQLJ-Based Java Method
An SQLJ program is a Java program that contains embedded SQL/MX statements in
SQLJ clauses. You can use a method of an SQLJ class file to create an SPJ that
performs SQL operations on an SQL/MP or SQL/MX database.
For example, the adjustSalary() method in the Payroll class adjusts an
employee’s salary in the EMPLOYEE table:
public class Payroll {
public static void adjustSalary( BigDecimal empNum,
double percent,
BigDecimal[] newSalary )
throws SQLException
{
#sql { MODULE samdbcat.persnl.payrollmod };
#sql { UPDATE samdbcat.persnl.employee
SET salary = salary * (1 + (:percent / 100 ))
WHERE empNum = :empNum };
#sql { SELECT salary
INTO :(newSalary[0])
FROM samdbcat.persnl.employee
WHERE empNum = :empNum };
}
}
To register this method as an SPJ in NonStop SQL/MX, use a CREATE PROCEDURE
statement. For details, see Section 4, Registering SPJs in NonStop SQL/MX.
Note. HP NonStop SQL/MX SQLJ (product T1232) has reached MATURE support status,
meaning that requests for enhancements (RFEs) are not considered and that only critical
defects are repaired. To develop SPJ methods that access SQL/MP or SQL/MX databases,
use JDBC/MX instead of SQLJ. For more information, see JDBC/MX-Based Java Method
on
page 3-6.