db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kristian Waagan <Kristian.Waa...@Sun.COM>
Subject Re: Problems create SQL Function
Date Mon, 18 May 2009 12:38:09 GMT
dacia wrote:
> Hi there
>
> I try to create some SQL function, but I stuck:
>
> [code]
> create function getDate(timeNumber bigint) returns date
>   
>> language java external name
>> 'java.util.Date(time)'
>> parameter style java no sql;
>>     
> 0 rows inserted/updated/deleted
> [/code]
>
> now:
>
> [code]
> ij> values getDate(1234566712345667789);
> ERROR 42X51: The class 'java.util' does not exist or is inaccessible. This
> can happen if the class is not public.
> ERROR XJ001: Java exception: 'java.util: java.lang.ClassNotFoundException'.
> [/code]
>
>
> What is wrong ?
>   

Hi,

You have to specify a public static method as the external name.
In the code you posted, Derby tries to find the class java.util and the 
static method Date. Since there is no such class nor method, it fails.

Unless you find a public static method in the Java API that returns a 
Date, I think you need to write your own wrapper method, for instance:
public class MyClass {
    public static java.util.Date getDate(long instant) {
       return new java.util.Date(instant);
    }
}

The external name here would be 'MyClass.getDate', or 
'MyClass.getDate(long)' (I think).
Note that the method doesn't need to have the same name as the function 
you declare. The class you write has to be on the classpath for Derby to 
access it (unless you install a Jar file in the database).


Hope this helps,
-- 
Kristian

>  Thanx
>   


Mime
View raw message