db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Knut Anders Hatlen <knut.hat...@oracle.com>
Subject Re: UDT and java arrays
Date Wed, 09 Nov 2011 10:51:43 GMT
Karl Weber <karl.weber99@googlemail.com> writes:

> Hi,
>
> Derby does support UDTs. One can use any java.io.Serializable java class as a 
> UDT.
>
> On the other hand, derby does not support SQL ARRAY types.
>
> However, every java array is an object that implements java.io.Serializable, 
> so can one define a UTD of the form
>
> CREATE TYPE APP.DARRAY
> 	EXTERNAL NAME 'double[]'
> 	LANGUAGE JAVA;
> ?
> ij does not complain. It also allows to use it in a table definition, e.g.
>
> ij> CREATE TYPE APP.DARRAY
>> EXTERNAL NAME 'double[]'
>> LANGUAGE JAVA;
> 0 Zeilen eingefügt/aktualisiert/gelöscht
> ij> create table XXX (
>> ASDF APP.DARRAY
>> );
> 0 Zeilen eingefügt/aktualisiert/gelöscht
>
> However, how do I insert values into this table, using normal SQL and using 
> the JDBC API?

Hi Karl,

The easiest way is to insert values using the JDBC API, like this:

    PreparedStatement ps = c.prepareStatement("INSERT INTO XXX VALUES ?");
    ps.setObject(1, new double[] { 1, 2, 3 });
    ps.executeUpdate();

If you want to do it from ij, you'll have to create a user-defined
function that returns the array you want to insert, and call that
function in the insert statement.

class StoredFunctions {
    public static double[] createArray(...) {
        double[] array;
        ...
        return array;
    }

ij> create function create_array () returns APP.DARRAY
     language java parameter style java
     external name 'Funcs.createArray';

ij> insert into xxx values create_array(...);

Hope this helps,

-- 
Knut Anders

Mime
View raw message