Alan Burlison wrote:
I have a Java database-side function that does a simple lookup of a
string on a reference table and returns the corresponding integer. If
the string can't be found I want to return NULL, but if I return a
Java null I get a database exception rather than the desired behaviour:
Error: java.sql.SQLException: The exception
'java.lang.NullPointerException' was thrown while evaluating an
expression., SQL State: 38000, Error Code: -1
How do I return a 'database' NULL from a database-side Java function?
Thanks,
Hi Alan,
It is hard to say where the NullPointerException originates. Could you
post a reproducible test case and the full stack trace from derby.log?
In general, you should be able to return null from user-written
functions. The following experiment on the 10.4 mainline shows this:
First I write a simple class:
public class z
{
public static String returnsNull()
{ return null; }
}
Then I register and run the function under ij:
ij> create function returnsNull()
returns varchar( 30 )
language java
parameter style java
no sql
external name 'z.returnsNull'
;
0 rows inserted/updated/deleted
ij> values ( returnsNull() );
1
--------------------------------------------------------------------------------------------------------------------------------
NULL
1 row selected
Regards,
-Rick