db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dacia <axel.tisc...@gmx.de>
Subject Re: Problems create SQL Function
Date Tue, 19 May 2009 13:09:17 GMT

Got it ! :-p

Create your java class in your favorit text editor.
Compile it (I do not know if this is really needed, I did !)
create a jar file containing both your .class and your .java file !!! <- The
.java was missing  !!

in ij do:
ij>call sqlj.install_jar('<path to jar file>','<alias name as you like>',0);
Statement executed.
( a copy of the jar is now availiable in derby.system.home / <databasename>
/ jar )
ij>call syscs_util.syscs_set_database_property
('derby.database.classpath','<alias name of above>');
Statement executed.
ij> create function <beCreative>(<param-name> <Derby Data Type>) returns
<Derby Data Type>
> language java external name
> '<java class name>.<method name>'
> parameter style java no sql;
0 rows inserted/updated/deleted

Run your function:
ij>values <yourFunction>(<param\>);

this should work.

CAVEAT: Be sure, the return type of your java method is compatible to the
return type of the defined function. e.g.
If the expected return type of your function is date the method must have
java.sql.date as return type.

public static java.sql.Date getDate(final long instant) {
      java.util.Date d= new java.util.Date(instant);
      return new java.sql.Date(d.getTime());
 }

To find the imported files in the database:
select s.schemaname, f.filename
from sys.sysschemas s, sys.sysfiles f
 where s.schemaid=f.schemaid;
-- 
View this message in context: http://www.nabble.com/Problems-create-SQL-Function-tp23595863p23616098.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.


Mime
View raw message