Re: Proper syntax for passing double array t o java language procedure

Fred Toussi via Hsqldb-user <[email protected]> Thu, 05 Aug 2021 09:27:06 +0100
Newsgroups gmane.comp.java.hsqldb.user
Message-ID <[email protected]>
This won't work for two reasons. SQL arrays are copied when the call is made so your sorting is done on the copy, not the original. Also Java arrays should not be primitive arrays.

Regarding syntax, the Array parameters in Java methods should be defined as java.sql.Array for IN parameters and as Array[] for INOUT and OUT params.

Something like these examples might work:

CREATE PROCEDURE sort(INOUT a DOUBLE ARRAY)
public static void sort(java.sql.Array[] a) {
    Array arr = a[0];
    Double[] darr = (Double[]) arr.getArray();

    // modify darr
    a[0] = modarr; // use this if you return a different Array object 
}

CREATE FUNCTION sort(a DOUBLE ARRAY) RETURNS DOUBLE ARRAY
public static void Double[] = sort(java.sql.Array[] a) {
     // sort and other stuff
    return a;
}


On Thu, Aug 5, 2021, at 02:36, Jorge Garcia de Alba wrote:
> Hello,
> 
> I am trying to create the java language procedure below but I keep
> getting an error and I think it is because I am not using proper
> syntax. How would you declare double array in java language procedure
> signature?
> 
> -----This is example sort method is in my LPModel class-----
> 
> public static void sort(double[] a) {
>         Arrays.sort(a);
>         //Other stuff
>     }
> 
> -----This the java language procedure I am trying to create-----
> 
> CREATE PROCEDURE sort(a DOUBLE ARRAY?)
> NO SQL
> LANGUAGE JAVA PARAMETER STYLE JAVA
> EXTERNAL NAME 'CLASSPATH:io.github.xjrga.linearprogram.LPModel.sort';
> 
> -----
> 
> An error occurred when executing the SQL command:
> CREATE PROCEDURE  sort(a DOUBLE)
>  NO SQL
> LANGUAGE JAVA PARAMETER STYLE JAVA
>  EXTERNAL NAME 'CLASSPATH:io.github.xjrga.linearprogram.LPModel.sort';
> 
> Java execution: unresolved class name, method name or signature [SQL
> State=46103, DB Errorcode=-6013]
> 1 statement failed.
> 
> 
> _______________________________________________
> Hsqldb-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/hsqldb-user
>