Java class datatypes and Java primitive datatypes handle null argument values in different ways.
Java object datatypes that are classes—such as java.lang.Integer, java.lang.String, java.lang.byte[], and java.sql.Timestamp—can hold both actual values and null reference values.
Java primitive datatypes—such as boolean, byte, short, and int—have no representation for a null value. They can hold only non-null values.
When a Java method is invoked that causes a SQL null value to be passed as an argument to a Java parameter whose datatype is a Java class, it is passed as a Java null reference value.When a SQL null value is passed as an argument to a Java parameter of a Java primitive datatype, however, an exception is raised because the Java primitive datatype has no representation for a null value.
Typically, you will write Java methods that specify Java parameter datatypes that are classes. In this case, nulls are handled without raising an exception. If you choose to write Java functions that use Java parameters that cannot handle null values, you can either:
Include the returns null on null input clause when you create the SQLJ function, or
Invoke the SQLJ function using a case or other conditional expression to test for null values and call the SQLJ function only for the non-null values.
You can handle expected nulls when you create the SQLJ function or when you call it. The following sections describe both scenarios, and reference this method:
public static String job(int jc) throws SQLException { if (jc==1) return “Admin”;
else if (jc==2) return “Sales”; else if (jc==3) return “Clerk”; else return “unknown jobcode”; }