I'm driving Windows XP and could use a tip on installing a function
written in Java.
1. I created the a Java jar file, named UdfUtils.jar, from the Java
source file shown below:
2. I copied the jar file to c:\Program Files\IBM\SQLLIB\FUNCTION
3. From the db2 command line I exectued call sqlj.refresh_classes()
4. I defined a function using the ddl also shown below
Now ...
When executing the statement
select RegExp('.*doc.*',resume) from {username}.EMP_RESUME
nothing happens.
( {username} is my DB2 username).
I have a hunch that the source of the problem is that the jar file and
class are never found - e.g. call.refresh_classes() isn't working for
me.
Also, separately, I've tried :
call.sqlj.install_jar('file:c:/pathtomyjar/jars/UdfUtils.jar','SAMPLE')
to locate my jar. I tried many variations of the above but must be
missing some syntax thing.
Thanks in advance.
package com.rhi.bbb.udf.utils;
import java.sql.Clob;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import COM.ibm.db2.app.UDF;
public class RegExp extends UDF {
public static int Match(java.lang.String pattern, java.sql.Clob clob) {
{
try
{
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(
clob.getSubString(Long.parseLong("1"), (int)clob.length()) );
if ( m.matches() ) {
return 1;
}
return 0;
}
catch (Exception e)
{
return 0;
}
}
}
CREATE FUNCTION RegExp(pattern VARCHAR(2048), string CLOB(10M))
RETURNS INTEGER
FENCED
VARIANT
NO SQL
LANGUAGE JAVA
PARAMETER STYLE JAVA
EXTERNAL NAME 'com.rhi.bbb.udf.utils.RegExp!Match'