473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Seek newbee Java UDF installation tip

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'

Apr 6 '06 #1
3 1987
gi*******************@yahoo.com wrote:
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.
What means "nothing happens"? Does DB2 just sit there and you wait? Or
does an error come back?
( {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.


If the class is not found, you'll get an error message saying so right away.
So I assume you experience a hang and that is most probably due to the code
in your function.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Apr 6 '06 #2
No hang. The method always returns null.

Apr 6 '06 #3
gi*******************@yahoo.com wrote:
No hang. The method always returns null.


Does it return a SQL NULL or a 0 (zero)? I'd suspect the latter because
this is what you are returing when an exception occurs. The
java.util.regex pattern is available since Java 1.4. Are you sure that
you're using this version with your DB2 instance?

I would recommend that you do not intercept an exception and simply return 0
without providing some more error information to DB2. You can either
simply pass on the exception, or you use the setSQLstate() and the
setSQLmessage() methods inherited from the UDF class. At the current
stage, I'd probably co with this:

public class RegExp extends UDF {

public static int Match(java.lang.String pattern, java.sql.Clob clob) {
{
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(
clob.getSubString(Long.parseLong("1"), (int)clob.length()) );
if ( m.matches() ) {
return 1;
}
return 0;
}
}

Call the function - it should give you some error about an exception, I
guess. Then have a look at the db2diag.log file where you will find the
exception and stack dump.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Apr 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phillip Montgomery | last post by:
Hello all; I'm trying to debug an issue with a java script called, SelectSockets. It appears to be a fairly common one found on the web. I downloaded the SGI Java v1.4.1 installation from SGI's...
4
by: Laura P | last post by:
Hi, I wasn't sure whether this should be posted in the Java are or in a Solaris thread, so I shall post it in both. Sorry for the duplication. I am new to Solaris and am having trouble...
1
by: Krist | last post by:
Hi All, Our customer has just decided to choose as development standard. The application is HR application with report. While many like Web client, Java application/thick client is still...
9
by: vegetax | last post by:
I was a java developer one year ago ,before i moved to python i realy liked it at the beggining, but i got very disapointed lately since my previus two python proyects where relatively big,and...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
0
by: rajamohamed05 | last post by:
In this shield used to create setup file for our project and install to anywhere. In Installation shield support visual basic 6.0,.Net(windows application),Java(awt and swing application). This...
0
by: rajamohamed05 | last post by:
In this shield used to create setup file for our project and install to anywhere. In Installation shield support visual basic 6.0,.Net(windows application),Java(awt and swing application). This...
0
by: Brad Baker | last post by:
Our developers are calling a java application from an ASP/ASP.net page. Excerpt as follows: ---- Dim a_jvmargs(1) a_jvmargs(0)= "-Djava.class.path=C:\Program...
1
by: gimme_this_gimme_that | last post by:
Hello fellow DB2ers! I have a new DB2 Express-C (version 9.5) installation running on Vista Business. I'm able to create new databases using the "create db dbname" command. I'm setting...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.