Topic
1 reply Latest Post - ‏2007-11-17T23:35:20Z by SystemAdmin
SystemAdmin
SystemAdmin
1525 Posts
ACCEPTED ANSWER

Pinned topic Implementing java functions

‏2007-11-15T16:15:51Z |
Hello,

I would like to use the java.lang.String.matches(...) function in the DB. The documentation gives the example
CREATE FUNCTION TO_DEGREES(RADIANS DOUBLE) RETURNS DOUBLE
PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA
EXTERNAL NAME 'java.lang.Math.toDegrees'

but we cannot apply this example 1:1 to string functions, because we have to specify the string itself as a parameter and secondly because we cannot specify a boolean as return value. Thus the following is not possible:
CREATE FUNCTION MATCHES(string CHAR, regex CHAR) RETURNS SMALLINT
PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA
EXTERNAL NAME 'java.lang.String.matches'

So we have to write our own function, isn't it?
final String strCreateFunctionMatch =
"CREATE FUNCTION myMatch(string CHAR, regex CHAR) RETURNS INT "+
"LANGUAGE JAVA "+
"PARAMETER STYLE JAVA NO SQL "+
"EXTERNAL NAME 'MyFile.myMatch'";

stmt.execute(strCreateFunctionMatch);



Am I right so far? You may well guess that I didn't succeed, but let's go step by step.

Regards
Jörg
Updated on 2007-11-17T23:35:20Z at 2007-11-17T23:35:20Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    1525 Posts
    ACCEPTED ANSWER

    Re: Implementing java functions

    ‏2007-11-17T23:35:20Z  in response to SystemAdmin
    Yes, so far it's alright. The error was only afterwards.