By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,812 Members | 863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,812 IT Pros & Developers. It's quick & easy.

Java UDF Question

P: n/a
I am writing Java UDFs using DB2 V8.2 (Fixpack 8) on Windows XP.

I would like to create some common code classes that are visible to the UDFs
on my system but I'm not having a lot of luck so far. I'm wondering if I'm
trying to do the impossible or if my technique is just wrong.

One of the common code classes I want to write contains code to open, write
and close a flat file that can be used for debugging. I'd like that class to
be visible to all of my Java UDFs so that I don't have to duplicate that
code in each and every Java UDF.

However, before I go that far, I decided to make a simple class that is
accessible to a Java class containing a UDF. I compiled it and then put the
resulting .class file in c:\Program Files\IBM\SQLLIB\FUNCTION, hoping that
my UDF would see it. However, when I execute the UDF that is supposed to use
it, the UDF fails on a NoClassDefFoundError.

(The UDF itself is in a Jar file at c:\Program
Files\IBM\SQLLIB\FUNCTION\jar\RHINO but that didn't seem the right place to
put a standalone class. However, when I tried copying my common code .class
file there anyway, the UDF failed on the exact same error.)

So, have I simply put the .class file in the wrong place? If so, where is
the right place?

Or is it simply not possible for the UDF to see any class other than itself?
In this case, I will have to duplicate my common code in every UDF that
needs debugging capability, which seems very redundant.

I can't find anything in the manuals that specifically says that a Java UDF
can or cannot see anything outside its own class.

--
Rhino
Nov 12 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Rhino wrote:
I am writing Java UDFs using DB2 V8.2 (Fixpack 8) on Windows XP.

I would like to create some common code classes that are visible to the
UDFs on my system but I'm not having a lot of luck so far. I'm wondering
if I'm trying to do the impossible or if my technique is just wrong.

One of the common code classes I want to write contains code to open,
write and close a flat file that can be used for debugging. I'd like that
class to be visible to all of my Java UDFs so that I don't have to
duplicate that code in each and every Java UDF.

However, before I go that far, I decided to make a simple class that is
accessible to a Java class containing a UDF. I compiled it and then put
the resulting .class file in c:\Program Files\IBM\SQLLIB\FUNCTION, hoping
that my UDF would see it. However, when I execute the UDF that is supposed
to use it, the UDF fails on a NoClassDefFoundError.

(The UDF itself is in a Jar file at c:\Program
Files\IBM\SQLLIB\FUNCTION\jar\RHINO but that didn't seem the right place
to put a standalone class. However, when I tried copying my common code
.class file there anyway, the UDF failed on the exact same error.)

So, have I simply put the .class file in the wrong place? If so, where is
the right place?

Or is it simply not possible for the UDF to see any class other than
itself? In this case, I will have to duplicate my common code in every UDF
that needs debugging capability, which seems very redundant.

I can't find anything in the manuals that specifically says that a Java
UDF can or cannot see anything outside its own class.


Java UDFs are just like any other Java program (except that the entry point
is not "main" but rather the method specified in the CREATE FUNCTION
statement). Per default, sqllib/function/ is in the classpath with which
the JVM is started by DB2. I had several situations where I had a series
of classes in the sqllib/function/ directory (each in their own .class
file) and they did work together quite nicely.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #2

P: n/a
Is sqllib\function on the system classpath? As long as the class is on
the system classpath, db2 should be able to find it. Note that the
entire instance share a single classpath and that might cause problem
if you have the same class file in various paths. A more customizable
classpath for each java routien is probably something DB2 should
implement in the future.

Nov 12 '05 #3

P: n/a

"Knut Stolze" <st****@de.ibm.com> wrote in message
news:d1**********@fsuj29.rz.uni-jena.de...
Rhino wrote:
I am writing Java UDFs using DB2 V8.2 (Fixpack 8) on Windows XP.

I would like to create some common code classes that are visible to the
UDFs on my system but I'm not having a lot of luck so far. I'm wondering
if I'm trying to do the impossible or if my technique is just wrong.

One of the common code classes I want to write contains code to open,
write and close a flat file that can be used for debugging. I'd like that class to be visible to all of my Java UDFs so that I don't have to
duplicate that code in each and every Java UDF.

However, before I go that far, I decided to make a simple class that is
accessible to a Java class containing a UDF. I compiled it and then put
the resulting .class file in c:\Program Files\IBM\SQLLIB\FUNCTION, hoping that my UDF would see it. However, when I execute the UDF that is supposed to use it, the UDF fails on a NoClassDefFoundError.

(The UDF itself is in a Jar file at c:\Program
Files\IBM\SQLLIB\FUNCTION\jar\RHINO but that didn't seem the right place
to put a standalone class. However, when I tried copying my common code
.class file there anyway, the UDF failed on the exact same error.)

So, have I simply put the .class file in the wrong place? If so, where is the right place?

Or is it simply not possible for the UDF to see any class other than
itself? In this case, I will have to duplicate my common code in every UDF that needs debugging capability, which seems very redundant.

I can't find anything in the manuals that specifically says that a Java
UDF can or cannot see anything outside its own class.
Java UDFs are just like any other Java program (except that the entry

point is not "main" but rather the method specified in the CREATE FUNCTION
statement). Per default, sqllib/function/ is in the classpath with which
the JVM is started by DB2. I had several situations where I had a series
of classes in the sqllib/function/ directory (each in their own .class
file) and they did work together quite nicely.

You haven't quite answered my question, probably because I didn't explain it
clearly enough.

If I define a Java class Foo, *which is NOT a Java UDF itself*, compile it
and put the .class file in sqllib/function, should a Java UDF be able to see
it? I'd like to be able to execute the methods in Foo from a Java UDF.

In other words, Foo is just a regular Java class and is *not* a UDF so no
CREATE FUNCTION was ever executed for it.

This is the situation I am trying to create but it isn't working. I'm
wondering if it is possible. If it is possible, I don't understand why my
UDF is not seeing the class when the UDF executes since I put the .class
file in sqllib/function.

Rhino
Nov 12 '05 #4

P: n/a

"W Gemini" <wg*****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Is sqllib\function on the system classpath?
Yes it is.
As long as the class is on
the system classpath, db2 should be able to find it.
Any idea why my non-UDF class isn't being found? I'm wondering if a UDF is
unable to see a class other than itself? Or maybe having a mix of classes in
jars (in sqllib/function/jar/schema) and standalone classes (in
sqllib/function) is causing problems?
Note that the
entire instance share a single classpath and that might cause problem
if you have the same class file in various paths. A more customizable
classpath for each java routien is probably something DB2 should
implement in the future.

I'm not sure that would be better ;-) I suspect that one customizable
classpath for the whole instance is better than having several customizable
classpaths. In the first scenario, at least it is obvious what the classpath
is; in the second scenario you'd never quite be sure which classpath is in
effect.

Rhino
Nov 12 '05 #5

P: n/a
Rhino wrote:
Java UDFs are just like any other Java program (except that the entry
point
is not "main" but rather the method specified in the CREATE FUNCTION
statement). Per default, sqllib/function/ is in the classpath with which
the JVM is started by DB2. I had several situations where I had a series
of classes in the sqllib/function/ directory (each in their own .class
file) and they did work together quite nicely.
You haven't quite answered my question, probably because I didn't explain
it clearly enough.

If I define a Java class Foo, *which is NOT a Java UDF itself*, compile it
and put the .class file in sqllib/function, should a Java UDF be able to
see it? I'd like to be able to execute the methods in Foo from a Java UDF.

In other words, Foo is just a regular Java class and is *not* a UDF so no
CREATE FUNCTION was ever executed for it.


What I meant is that from a Java/JVM perspective, there is absolutely
nothing special about Java UDFs that get called by the DB2 engine. A Java
UDF is like any other Java program. A Java program can invoke methods from
other classes, and so can a Java UDF. There is nothing in DB2 to prevent
you from calling methods of other classes.
This is the situation I am trying to create but it isn't working. I'm
wondering if it is possible. If it is possible, I don't understand why my
UDF is not seeing the class when the UDF executes since I put the .class
file in sqllib/function.


Something in your setup is amiss, I'd say. You should have a look at your
CLASSPATH that is available inside the UDF, i.e. what is the
java.class.path property set to? DB2 adds a few paths to the path set in
your enviroment.

The first result on google gave the V7 documentation, but you should also
find some relevant information there:
http://publib.boulder.ibm.com/infoce...0/db2a0162.htm

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #6

P: n/a

"Knut Stolze" <st****@de.ibm.com> wrote in message
news:d1**********@fsuj29.rz.uni-jena.de...
Rhino wrote:
Java UDFs are just like any other Java program (except that the entry
point
is not "main" but rather the method specified in the CREATE FUNCTION
statement). Per default, sqllib/function/ is in the classpath with which the JVM is started by DB2. I had several situations where I had a series of classes in the sqllib/function/ directory (each in their own .class
file) and they did work together quite nicely.
You haven't quite answered my question, probably because I didn't explain it clearly enough.

If I define a Java class Foo, *which is NOT a Java UDF itself*, compile it and put the .class file in sqllib/function, should a Java UDF be able to
see it? I'd like to be able to execute the methods in Foo from a Java UDF.
In other words, Foo is just a regular Java class and is *not* a UDF so no CREATE FUNCTION was ever executed for it.


What I meant is that from a Java/JVM perspective, there is absolutely
nothing special about Java UDFs that get called by the DB2 engine. A Java
UDF is like any other Java program. A Java program can invoke methods

from other classes, and so can a Java UDF. There is nothing in DB2 to prevent
you from calling methods of other classes.
Excellent! That is exactly what I was hoping to hear. Now I know that it is
only my setup that has a problem, not that the whole thing is impossible
from the start.
This is the situation I am trying to create but it isn't working. I'm
wondering if it is possible. If it is possible, I don't understand why my UDF is not seeing the class when the UDF executes since I put the .class
file in sqllib/function.


Something in your setup is amiss, I'd say. You should have a look at your
CLASSPATH that is available inside the UDF, i.e. what is the
java.class.path property set to? DB2 adds a few paths to the path set in
your enviroment.

The first result on google gave the V7 documentation, but you should also
find some relevant information there:

http://publib.boulder.ibm.com/infoce...0/db2a0162.htm

Thank you! Now I should be able to sort out the problem.

Rhino
Nov 12 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.