473,385 Members | 1,712 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,385 software developers and data experts.

Clob as parameter in Java UDF

I have the following Java code :

package com.rhi.bb.udf.utils;

import java.sql.Clob;
import java.sql.SQLException;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

// import COM.ibm.db2.app.UDF;

public class RegExp {

public static int MatchClob(String pattern, java.sql.Clob[] clob)
throws SQLException
{
// I tried making clob be both a Clob[] and a Clob but the error
message was the same
if ( 0 == clob.length ) {
return 2;
}
try {
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(
clob[0].getSubString(Long.parseLong("1"), (int)clob[0].length()) );
if ( m.matches() ) {
return 1;
}
return 0;
} catch (Exception ex) {
throw new SQLException("RegExp.MatchClob failed " + ex);
}
}
}

I know DB2 finds the class file because I've placed other UDFs in the
RegExp class and they work.
Then:

drop function MATCH_CLOB;
call sqlj.refresh_classes();

CREATE FUNCTION MATCH_CLOB(pattern VARCHAR(4000), input_clob CLOB(1M))
RETURNS INTEGER
FENCED
VARIANT
NO SQL
LANGUAGE JAVA
PARAMETER STYLE JAVA
EXTERNAL NAME 'com.rhi.bb.udf.utils.RegExp!MatchClob';
This is the resulting error message :
[IBM][CLI Driver][DB2/NT] SQL4302N Procedure or user-defined function
"EMMMCL01.MATCH_CLOB", specific name "SQL060815120135200" aborted with
an exception "class COM.ibm.db2.app.ClobWithD". SQLSTATE=38501\ d\ a"

Any suggestions?

Thanks.
Here is the full stack trace.
aqt d88-e04 EXIT SQLErrorW with return code 0
(SQL_SUCCESS)
HENV 020A12A0
HDBC 020A13A0
HSTMT 020A1D20
WCHAR * 0x0012EB80 (NYI)
SDWORD * 0x0012ED48 (-4302)
WCHAR * 0x0012E780 [ 207] "[IBM][CLI Driver][DB2/NT]
SQL4302N Procedure or user-defined function "EMMMCL01.MATCH_CLOB",
specific name "SQL060815120135200" aborted with an exception "class
COM.ibm.db2.app.ClobWithD". SQLSTATE=38501\ d\ a"
SWORD 512
SWORD * 0x0012ED44 (207)

aqt d88-e04 ENTER SQLErrorW
HENV 020A12A0
HDBC 020A13A0
HSTMT 020A1D20
WCHAR * 0x0012EB80 (NYI)
SDWORD * 0x0012ED48
WCHAR * 0x0012E780
SWORD 512
SWORD * 0x0012ED44

aqt d88-e04 EXIT SQLErrorW with return code 100
(SQL_NO_DATA_FOUND)
HENV 020A12A0
HDBC 020A13A0
HSTMT 020A1D20
WCHAR * 0x0012EB80 (NYI)
SDWORD * 0x0012ED48
WCHAR * 0x0012E780
SWORD 512
SWORD * 0x0012ED44

Aug 15 '06 #1
8 4970
gi*******************@yahoo.com wrote:
I have the following Java code :

package com.rhi.bb.udf.utils;

import java.sql.Clob;
import java.sql.SQLException;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

// import COM.ibm.db2.app.UDF;

public class RegExp {

public static int MatchClob(String pattern, java.sql.Clob[] clob)
throws SQLException
{
// I tried making clob be both a Clob[] and a Clob but the error
message was the same
if ( 0 == clob.length ) {
return 2;
}
try {
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(
clob[0].getSubString(Long.parseLong("1"), (int)clob[0].length()) );
if ( m.matches() ) {
return 1;
}
return 0;
} catch (Exception ex) {
throw new SQLException("RegExp.MatchClob failed " + ex);
}
}
}

I know DB2 finds the class file because I've placed other UDFs in the
RegExp class and they work.
Then:

drop function MATCH_CLOB;
call sqlj.refresh_classes();

CREATE FUNCTION MATCH_CLOB(pattern VARCHAR(4000), input_clob CLOB(1M))
RETURNS INTEGER
FENCED
VARIANT
NO SQL
LANGUAGE JAVA
PARAMETER STYLE JAVA
EXTERNAL NAME 'com.rhi.bb.udf.utils.RegExp!MatchClob';
This is the resulting error message :
[IBM][CLI Driver][DB2/NT] SQL4302N Procedure or user-defined function
"EMMMCL01.MATCH_CLOB", specific name "SQL060815120135200" aborted with
an exception "class COM.ibm.db2.app.ClobWithD". SQLSTATE=38501\ d\ a"

Any suggestions?
Have a look at the db2diag.log file (or just run the "db2diag" executable).
You will find the full stack trace of the exception there, including the
specific exception information. That should help us along in figuring out
what's going on.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Aug 15 '06 #2
Thanks Knut,

I get that it's not finding the MatchClob method.

But I have a MatchVarchar method in the same RegEx class and DB2 finds
that OK.

I've also stopped and restarted the server.
Here it is:

M
2006-08-15-12.37.01.804000-420 I364795H467 LEVEL: Warning^M
PID : 604 TID : 3064 PROC : db2fmp.exe^M
INSTANCE: DB2 NODE : 000^M
FUNCTION: DB2 UDB, BSU Java support, sqlejCallJavaRoutine_dll,
probe:130^M
MESSAGE : JNI GetMethodID failed. class:
DATA #1 : Hexdump, 28 bytes^M
0x018AD230 : 636F 6D2F 7268 692F 626F 622F 7564 662F
com/rhi/bb/udf/^M
0x018AD240 : 7574 696C 732F 5265 6745 7870 utils/RegExp^M
^M
2006-08-15-12.37.01.804000-420 I365264H390 LEVEL: Warning^M
PID : 604 TID : 3064 PROC : db2fmp.exe^M
INSTANCE: DB2 NODE : 000^M
FUNCTION: DB2 UDB, BSU Java support, sqlejCallJavaRoutine_dll,
probe:140^M
MESSAGE : JNI GetMethodID failed. method:
DATA #1 : Hexdump, 9 bytes^M
0x018AD24D : 4D61 7463 6843 6C6F 62 MatchClob^M
^M
2006-08-15-12.37.01.804000-420 I365656H537 LEVEL: Warning^M
PID : 604 TID : 3064 PROC : db2fmp.exe^M
INSTANCE: DB2 NODE : 000^M
FUNCTION: DB2 UDB, BSU Java support, sqlejCallJavaRoutine_dll,
probe:150^M
MESSAGE : JNI GetMethodID failed. signature:
DATA #1 : Hexdump, 36 bytes^M
0x018AD290 : 284C 6A61 7661 2F6C 616E 672F 5374 7269
(Ljava/lang/Stri^M
0x018AD2A0 : 6E67 3B4C 6A61 7661 2F73 716C 2F43 6C6F
ng;Ljava/sql/Clo^M
0x018AD2B0 : 623B 2949 b;)I^M
^M
2006-08-15-12.37.01.804000-420 E366195H375 LEVEL: Warning^M
PID : 604 TID : 3064 PROC : db2fmp.exe^M
INSTANCE: DB2 NODE : 000^M
FUNCTION: DB2 UDB, BSU Java support, sqlejLogException, probe:10^M
MESSAGE : ADM10000W A Java exception has been caught. The Java stack
^M
traceback has been written to the db2diag.log.^M
^M
2006-08-15-12.37.01.804000-420 I366572H384 LEVEL: Warning^M
PID : 604 TID : 3064 PROC : db2fmp.exe^M
INSTANCE: DB2 NODE : 000^M
FUNCTION: DB2 UDB, BSU Java support, sqlejLogException, probe:10^M
MESSAGE : java.lang.NoSuchMethodError: MatchClob^M
DATA #1 : Hexdump, 4 bytes^M
0x01AAF430 : 0000 0000 ....^M
^M
2006-08-15-12.37.01.804000-420 I366958H384 LEVEL: Warning^M
PID : 604 TID : 3064 PROC : db2fmp.exe^M
INSTANCE: DB2 NODE : 000^M
FUNCTION: DB2 UDB, routine_infrastructure, sqlerJavaCallRoutine,
probe:30^M
MESSAGE : Error from DB2ER CallUDF. RC:
DATA #1 : Hexdump, 4 bytes^M
0x01AAF988 : 2EEF FFFF ....^M

Aug 15 '06 #3
gi*******************@yahoo.com wrote:
Thanks Knut,

I get that it's not finding the MatchClob method.

But I have a MatchVarchar method in the same RegEx class and DB2 finds
that OK.
Have you removed the [] in the method signature? IIRC, this is not needed.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Aug 15 '06 #4
Hi Knut,

Here is the result of db2diag.exe when the Clob is not an array:

2006-08-15-15.58.28.570000-420 I376819H299 LEVEL: Warning^M
PID : 628 TID : 2196 PROC : db2fmp.exe^M
INSTANCE: DB2 NODE : 000^M
FUNCTION: DB2 UDB, BSU Java support, sqlejCallJavaRoutine_dll,
probe:370^M
MESSAGE : Java routine exited with exception.^M
^M
2006-08-15-15.58.28.570000-420 E377120H375 LEVEL: Warning^M
PID : 628 TID : 2196 PROC : db2fmp.exe^M
INSTANCE: DB2 NODE : 000^M
FUNCTION: DB2 UDB, BSU Java support, sqlejLogException, probe:10^M
MESSAGE : ADM10000W A Java exception has been caught. The Java stack
^M
traceback has been written to the db2diag.log.^M
^M
2006-08-15-15.58.28.570000-420 I377497H547 LEVEL: Warning^M
PID : 628 TID : 2196 PROC : db2fmp.exe^M
INSTANCE: DB2 NODE : 000^M
FUNCTION: DB2 UDB, BSU Java support, sqlejLogException, probe:10^M
DATA #1 : String, 184 bytes^M
java.lang.IncompatibleClassChangeError: class
COM.ibm.db2.app.ClobWithDB2Buffer does not implement interface
java.sql.Clob^M
at com.rhi.bob.udf.utils.RegExp.MatchClob(Unknown Source)^M
DATA #2 : Hexdump, 4 bytes^M
0x01AAF414 : 0000 0000 ....^M
^M
2006-08-15-15.58.28.570000-420 E378046H375 LEVEL: Warning^M
PID : 628 TID : 2196 PROC : db2fmp.exe^M
INSTANCE: DB2 NODE : 000^M
FUNCTION: DB2 UDB, BSU Java support, sqlejLogException, probe:10^M
MESSAGE : ADM10000W A Java exception has been caught. The Java stack
^M
traceback has been written to the db2diag.log.^M
^M
2006-08-15-15.58.28.570000-420 I378423H547 LEVEL: Warning^M
PID : 628 TID : 2196 PROC : db2fmp.exe^M
INSTANCE: DB2 NODE : 000^M
FUNCTION: DB2 UDB, BSU Java support, sqlejLogException, probe:10^M
DATA #1 : String, 184 bytes^M
java.lang.IncompatibleClassChangeError: class
COM.ibm.db2.app.ClobWithDB2Buffer does not implement interface
java.sql.Clob^M
at com.rhi.bob.udf.utils.RegExp.MatchClob(Unknown Source)^M
DATA #2 : Hexdump, 4 bytes^M
0x01AAF430 : 0000 0000 ....^M
^M
2006-08-15-15.58.28.570000-420 I378972H384 LEVEL: Warning^M
PID : 628 TID : 2196 PROC : db2fmp.exe^M
INSTANCE: DB2 NODE : 000^M
FUNCTION: DB2 UDB, routine_infrastructure, sqlerJavaCallRoutine,
probe:30^M
MESSAGE : Error from DB2ER CallUDF. RC:
DATA #1 : Hexdump, 4 bytes^M
0x01AAF988 : 32EF FFFF

Aug 15 '06 #5
gi*******************@yahoo.com wrote:
Here is the result of db2diag.exe when the Clob is not an array:

2006-08-15-15.58.28.570000-420 I377497H547 LEVEL: Warning
PID : 628 TID : 2196 PROC : db2fmp.exe
INSTANCE: DB2 NODE : 000
FUNCTION: DB2 UDB, BSU Java support, sqlejLogException, probe:10
DATA #1 : String, 184 bytes
java.lang.IncompatibleClassChangeError: class
COM.ibm.db2.app.ClobWithDB2Buffer does not implement interface
java.sql.Clob
at com.rhi.bob.udf.utils.RegExp.MatchClob(Unknown Source)
DATA #2 : Hexdump, 4 bytes
0x01AAF414 : 0000 0000 ....
That rings a bell. ;-)

Try to use COM.IBM.db2.app.Clob instead of java.sql.Clob.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Aug 15 '06 #6
I didn't find COM.IBM.db2.app.Clob in db2jcc.jar I found
COM.ibm.db2.app.Clob and used that.

Here's the result of db2diag.exe from executing

select MATCH_CLOB('\w{3}\d{2}',delme.lob) from delme;
2006-08-15-17.56.00.117000-420 I399029H467 LEVEL: Warning
PID : 3668 TID : 2676 PROC : db2fmp.exe
INSTANCE: DB2 NODE : 000
FUNCTION: DB2 UDB, BSU Java support, sqlejCallJavaRoutine_dll,
probe:130
MESSAGE : JNI GetMethodID failed. class:
DATA #1 : Hexdump, 28 bytes
0x018AD230 : 636F 6D2F 7268 692F 626F 622F 7564 662F com/rhi/bb/udf/
0x018AD240 : 7574 696C 732F 5265 6745 7870 utils/RegExp

2006-08-15-17.56.00.117000-420 I399498H390 LEVEL: Warning
PID : 3668 TID : 2676 PROC : db2fmp.exe
INSTANCE: DB2 NODE : 000
FUNCTION: DB2 UDB, BSU Java support, sqlejCallJavaRoutine_dll,
probe:140
MESSAGE : JNI GetMethodID failed. method:
DATA #1 : Hexdump, 9 bytes
0x018AD24D : 4D61 7463 6843 6C6F 62 MatchClob

2006-08-15-17.56.00.117000-420 I399890H537 LEVEL: Warning
PID : 3668 TID : 2676 PROC : db2fmp.exe
INSTANCE: DB2 NODE : 000
FUNCTION: DB2 UDB, BSU Java support, sqlejCallJavaRoutine_dll,
probe:150
MESSAGE : JNI GetMethodID failed. signature:
DATA #1 : Hexdump, 36 bytes
0x018AD290 : 284C 6A61 7661 2F6C 616E 672F 5374 7269
(Ljava/lang/Stri
0x018AD2A0 : 6E67 3B4C 6A61 7661 2F73 716C 2F43 6C6F
ng;Ljava/sql/Clo
0x018AD2B0 : 623B 2949 b;)I

2006-08-15-17.56.00.132000-420 E400429H375 LEVEL: Warning
PID : 3668 TID : 2676 PROC : db2fmp.exe
INSTANCE: DB2 NODE : 000
FUNCTION: DB2 UDB, BSU Java support, sqlejLogException, probe:10
MESSAGE : ADM10000W A Java exception has been caught. The Java stack
traceback has been written to the db2diag.log.

2006-08-15-17.56.00.132000-420 I400806H384 LEVEL: Warning
PID : 3668 TID : 2676 PROC : db2fmp.exe
INSTANCE: DB2 NODE : 000
FUNCTION: DB2 UDB, BSU Java support, sqlejLogException, probe:10
MESSAGE : java.lang.NoSuchMethodError: MatchClob
DATA #1 : Hexdump, 4 bytes
0x01AAF430 : 0000 0000 ....

2006-08-15-17.56.00.132000-420 I401192H384 LEVEL: Warning
PID : 3668 TID : 2676 PROC : db2fmp.exe
INSTANCE: DB2 NODE : 000
FUNCTION: DB2 UDB, routine_infrastructure, sqlerJavaCallRoutine,
probe:30
MESSAGE : Error from DB2ER CallUDF. RC:
DATA #1 : Hexdump, 4 bytes
0x01AAF988 : 2EEF FFFF ....

Also:

package com.rhi.bb.udf.utils;

import java.sql.Clob;
import java.sql.SQLException;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class RegExp {

public static int MatchClob(String pattern, COM.ibm.db2.app.Clob
clob) throws SQLException
{
if ( null == clob) {
return 2;
}
try {
Pattern p = Pattern.compile(pattern);
Long size = new Long(clob.size());
char[] cbuff = new char[size.intValue()];
clob.getReader().read(cbuff);
Matcher m = p.matcher( new String(cbuff) );
if ( m.matches() ) {
return 1;
}
return 0;
} catch (Exception ex) {
throw new SQLException("RegExp.MatchClob failed " + ex);
}
}

}
call sqlj.refresh_classes();
CREATE FUNCTION MATCH_CLOB(pattern VARCHAR(4000), input_clob CLOB(1M))
RETURNS INTEGER
FENCED
VARIANT
NO SQL
LANGUAGE JAVA
PARAMETER STYLE JAVA
EXTERNAL NAME 'com.rhi.bb.udf.utils.RegExp!MatchClob';

Aug 16 '06 #7
Yey!!

To use COM.ibm.db2.app.Clob my java class had to implement UDF and I
had to use parameter style DB2GENERAL and not parameter style Java.

This worked when placed in a jar in the Windows XP CLASSPATH:

package com.rhi.bb.utils.udf;

import COM.ibm.db2.app.Clob;
import COM.ibm.db2.app.UDF;

import java.sql.SQLException;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class RegExpUdf extends UDF {

public void MatchClob(String pattern, COM.ibm.db2.app.Clob clob,
int result) throws Exception
{
if ( null == clob) {
set(3,2);
return;
}
Pattern p = Pattern.compile(pattern);
Long size = new Long(clob.size());
char[] cbuff = new char[size.intValue()];
clob.getReader().read(cbuff);
Matcher m = p.matcher( new String(cbuff) );
if ( m.matches() ) {
set(3,1);
return;
}
set(3,0);
}

}
drop function MATCH_CLOB;
call sqlj.refresh_classes();

CREATE FUNCTION MATCH_CLOB(pattern VARCHAR(4000), clob CLOB(1048576))
RETURNS INTEGER
FENCED
NO SQL
LANGUAGE JAVA
DETERMINISTIC
PARAMETER STYLE DB2GENERAL
EXTERNAL NAME 'com.rhi.bb.utils.udf.RegExpUdf!MatchClob';

select MATCH_CLOB('\w{3}\d{2}',lob) from delme;
0
1

Aug 22 '06 #8
For those of you who might be interested ...

Here is the Java UDF for regular expression matching over varchars:

package com.rhi.bb.utils.udf;

import java.sql.SQLException;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class RegExp {

public static int MatchVarchar(String pattern, String varchar) throws
SQLException
{
try {
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher( varchar );
if ( m.matches() ) {
return 1;
}
return 0;
} catch (Exception ex) {
throw new SQLException("RegExp.MatchVarchar failed " +
ex.getCause());
}
}
}
drop function MATCH_VARCHAR;

call sqlj.refresh_classes();
CREATE FUNCTION MATCH_VARCHAR(pattern VARCHAR(4000), string
VARCHAR(4000))
RETURNS INTEGER
FENCED
VARIANT
NO SQL
LANGUAGE JAVA
PARAMETER STYLE JAVA
EXTERNAL NAME 'com.rhi.bob.utils.udf.RegExp!MatchVarchar';

select MATCH_VARCHAR('\w{3}\d{2}','abc33') from sysibm.sysdummy1;

Aug 23 '06 #9

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

Similar topics

1
by: Chris | last post by:
I use websphere connection pooling and had a failure attempting a CLOB.createTemporary. tempClob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION); Here's an excerpt of the exception...
0
by: thefirstwml | last post by:
Hi, I cannot view CLOB fields when I use the Sample Contents in the Control Center. When I insert values, I see the CLOB fields as blank. A fellow developer is using the exact same DB2 UDB...
1
by: Srinadh | last post by:
Hi all, We have files with about 20 to 30 fields per row. We are trying to update such files with about 60 rows as contiguous data in a CLOB field. It passes through. But when we try...
1
by: Khodr | last post by:
Hi everyone, I am calling an Oracle StoredProc that returns a CLOB data type value as an output parameter. What parameter data type should I use? >> I tried adLongVarChar and adVarChar with the...
2
by: Jason | last post by:
Hi, I was wondering if anyone could advise me on this. Right now I am setting up a DB2 UDB V8.2.3 database with UTF8 character set, which will work with a J2EE application running on...
3
by: egarobar | last post by:
I am using Access 2003 (on WinXP) to read from an Oracle db, where there is a table with a CLOB which is a variable-size text field. In the 'linked table' which is created in the Tables panel of...
0
by: *Davide* | last post by:
Hello, This query (PHP+Oracle) works: global $user,$pass,$sid; $db_charset = 'UTF8'; $db = OCILogon($user, $pass, $sid, $db_charset); $clob = OCINewDescriptor($db, OCI_D_LOB); $txt_clob =...
0
by: srinivasaraonagisetty | last post by:
hi, I am faceing one problem, while inserting the data in db2 using clob. actually i am writing this type code: public class DBParam { private InputStream inputstream; private static int...
0
by: Steve | last post by:
Hi All, Can someone tell me why I might see the following: StackTrace: java.lang.NullPointerException at oracle.sql.LobPlsqlUtil.plsql_freeTemporaryLob(LobPlsqlUtil.java:1378) at...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.