Karl Weber <[email protected]> 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