Neoview Guide to Stored Procedures in Java (R2.3, R2.4)
If you define the SQLSTATE to be outside the range of 38001 to 38999, Neoview SQL raises
SQLSTATE 39001, external routine invocation exception.
This example uses the throw statement in the SPJ method named numMonthlyOrders() to
raise a user-defined error condition when an invalid argument value is entered for the month:
public static void numMonthlyOrders(int month,
int[] numOrders)
throws java.sql.SQLException
{
if ( month < 1 || month > 12 )
{
throw new java.sql.SQLException (
"Invalid value for month. "
+ "Retry the CALL statement using a number "
+ "from 1 to 12 to represent the month.", "38001" );
}
....
}
For more information about the numMonthlyOrders() method, see the “MONTHLYORDERS
Procedure” (page 82).
For information about specific SQL errors, see the Neoview Messages Manual, which lists the
SQLCODE, SQLSTATE, message text, and cause-effect-recovery information for all Neoview
SQL errors.
Compiling and Packaging Java Classes
On the Neoview platform, the class files of SPJ methods must be packaged in Java archive (JAR)
files. After writing an SPJ method, compile the Java source file of the SPJ method into Java
bytecode and package the Java bytecode in a JAR file. A Java method that you register as an SPJ
might need to access, either directly or indirectly, other Java classes to operate properly. Those
Java classes might include other application classes. To enable an SPJ method to refer to other
application classes, put the application classes in the same JAR file as the SPJ class. All classes
stored in the same JAR file as the SPJ class are accessible by default to the SPJ method.
After writing the SPJ method:
1. Compile the Java source file into Java bytecode by using the Java programming language
compiler, javac:
javac Payroll.java
2. Put the SPJ class file and all associated class files into a Java archive (JAR) file:
jar cvf Payroll.jar Payroll.class
A manifest file is not needed for the JAR file.
Compiling and Packaging Java Classes 33