Handling null argument values

Java class datatypes and Java primitive datatypes handle null argument values in different ways.

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:

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”;
	}