Return-Path: X-Original-To: apmail-db-derby-user-archive@www.apache.org Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4FF7E10320 for ; Thu, 19 Dec 2013 13:21:15 +0000 (UTC) Received: (qmail 20239 invoked by uid 500); 19 Dec 2013 13:21:07 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 20175 invoked by uid 500); 19 Dec 2013 13:20:59 -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 20167 invoked by uid 99); 19 Dec 2013 13:20:58 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Dec 2013 13:20:58 +0000 X-ASF-Spam-Status: No, hits=-2.3 required=5.0 tests=FSL_NEW_HELO_USER,RCVD_IN_DNSWL_MED,SPF_PASS,UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of knut.hatlen@oracle.com designates 156.151.31.81 as permitted sender) Received: from [156.151.31.81] (HELO userp1040.oracle.com) (156.151.31.81) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Dec 2013 13:20:51 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id rBJDKSOw024497 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 19 Dec 2013 13:20:29 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rBJDKPNC007403 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 19 Dec 2013 13:20:26 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rBJDKPgx007395; Thu, 19 Dec 2013 13:20:25 GMT Received: from localhost (/10.172.139.141) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 19 Dec 2013 05:20:25 -0800 From: Knut Anders Hatlen To: Tim Dudgeon Cc: derby-user@db.apache.org Subject: Re: varargs with functions References: Mail-Copies-To: never Mail-Followup-To: Tim Dudgeon , derby-user@db.apache.org Date: Thu, 19 Dec 2013 14:20:23 +0100 In-Reply-To: (Tim Dudgeon's message of "Thu, 19 Dec 2013 11:29:17 +0000") Message-ID: User-Agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Source-IP: acsinet22.oracle.com [141.146.126.238] X-Virus-Checked: Checked by ClamAV on apache.org Tim Dudgeon writes: > I'm struggling with getting a function working that uses a Java static > method that uses varargs. > I understand this should work with 10.10.1.1? > > I create function like this: > > CREATE FUNCTION FORMAT_CPD_CODE > ( FORMAT VARCHAR(100), VAL INT ... ) > RETURNS VARCHAR(20) > PARAMETER STYLE DERBY > NO SQL LANGUAGE JAVA > EXTERNAL NAME 'java.lang.String.format' > > and use it like this: > > values(FORMAT_CPD_CODE('XYZ%08d', 123)) > > > But I get error: > > java.sql.SQLSyntaxErrorException: No method was found that matched the > method call java.lang.String.format(java.lang.String, int...), 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. > > Any suggestions on how to get this working? Hi Tim, Derby's method resolution currently requires the types in the signature to match exactly. That is, it doesn't accept Object for an INT parameter; it has to be int or java.lang.Integer. I think it should work if you create a thin wrapper method around String.format() with the correct signature. Something like this: public static String format(String format, Integer... args) { return String.format(format, (Object[]) args); } And then point to the wrapper method in the CREATE FUNCTION call. Hope this helps, -- Knut Anders