Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 4952 invoked from network); 19 May 2009 11:50:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 19 May 2009 11:50:12 -0000 Received: (qmail 89560 invoked by uid 500); 19 May 2009 11:50:11 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 89512 invoked by uid 500); 19 May 2009 11:50:11 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 89504 invoked by uid 99); 19 May 2009 11:50:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 May 2009 11:50:11 +0000 X-ASF-Spam-Status: No, hits=-4.0 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [192.18.6.21] (HELO gmp-eb-inf-1.sun.com) (192.18.6.21) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 May 2009 11:50:01 +0000 Received: from fe-emea-10.sun.com (gmp-eb-lb-2-fe3.eu.sun.com [192.18.6.12]) by gmp-eb-inf-1.sun.com (8.13.7+Sun/8.12.9) with ESMTP id n4JBnRHu016258 for ; Tue, 19 May 2009 11:49:39 GMT MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII; format=flowed Received: from conversion-daemon.fe-emea-10.sun.com by fe-emea-10.sun.com (Sun Java(tm) System Messaging Server 7u2-7.02 64bit (built Apr 16 2009)) id <0KJW000002HW0C00@fe-emea-10.sun.com> for derby-user@db.apache.org; Tue, 19 May 2009 12:49:27 +0100 (BST) Received: from [192.168.10.153] ([unknown] [84.208.133.36]) by fe-emea-10.sun.com (Sun Java(tm) System Messaging Server 7u2-7.02 64bit (built Apr 16 2009)) with ESMTPSA id <0KJW00J1A3IBBKB0@fe-emea-10.sun.com> for derby-user@db.apache.org; Tue, 19 May 2009 12:49:27 +0100 (BST) Date: Tue, 19 May 2009 13:49:22 +0200 From: Kristian Waagan Subject: Re: Problems create SQL Function In-reply-to: <23614219.post@talk.nabble.com> Sender: Kristian.Waagan@Sun.COM To: Derby Discussion Message-id: <4A129CC2.8010708@Sun.COM> References: <23595863.post@talk.nabble.com> <4A1156B1.3000501@Sun.COM> <23614219.post@talk.nabble.com> User-Agent: Thunderbird 2.0.0.21 (X11/20090323) X-Virus-Checked: Checked by ClamAV on apache.org dacia wrote: > Hi Kristian > > I tried this: > > java code: > public class DateFunctions { > > public static java.util.Date getDate(long instant) { > return new java.util.Date(instant); > } > } > > in ij: > ij>call sqlj.install_jar('DateFunctions.jar','DateFunctions',0); > Statement executed. > ij> create function getDate(timeNumber bigint) returns date >> language java external name >> 'DateFunctions.getDate' >> parameter style java no sql; > 0 rows inserted/updated/deleted > > ij>values getDate(123456789123456789); > ERROR 42X50: No method was found that matched the method call > DateFunctions.getDate(long), tried all combinations of object and primitive > types and any possible type conversion for any parameters the method call > may have. The method might exist but it is not public and/or static, or the > parameter types are not method invocation convertible. Would be good if also the expected return type was included in the error message here... > > ij>values getDate(Cast(123456789123456789 as bigint)); > ERROR 42X50:...... > > ij>select s.schemaname, f.filename >> from sys.sysschemas s, sys.sysfiles f >> where s.schemaid=f.schemaid; > SCHEMANAME | FILENAME > APP |DATEFUNCTIONS > 1 row selected > > Is there any way to verify, if the function is loaded and which parameters > are expected ? Not that I'm aware of, except for looking in the system tables. Anyone? > Or what did I wrong ? Sorry, I didn't think about the fact that you have to return a data type that Derby can handle (SQL). These are described in the Reference Manual under "Data types". In this case, java.util.Date was specified, but one of java.sql.Date, java.sql.Time or java.sql.Timestamp should be used. I had no problems invoking the function when doing that. I didn't create a Jar, just put the class on the classpath: ij version 10.6 ij> connect 'jdbc:derby:memory:mydb;create=true'; ij> create function getDate(timeNumber bigint) returns date > language java external name > 'DateFunctions.getDate' > parameter style java no sql; 0 rows inserted/updated/deleted ij> values getDate(23423423432); 1 ---------- 1970-09-29 1 row selected ij> Cheers, -- Kristian > > > > > Kristian Waagan-4 wrote: >> 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 >>> >> >> >