Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / March 2005

Tip: Looking for answers? Try searching our database.

Java UDF Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rhino - 21 Mar 2005 15:13 GMT
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.

Signature

Rhino

Knut Stolze - 21 Mar 2005 17:09 GMT
> I am writing Java UDFs using DB2 V8.2 (Fixpack 8) on Windows XP.
>
[quoted text clipped - 27 lines]
> 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.

Signature

Knut Stolze
Information Integration
IBM Germany / University of Jena

Rhino - 21 Mar 2005 18:38 GMT
> > I am writing Java UDFs using DB2 V8.2 (Fixpack 8) on Windows XP.
> >
[quoted text clipped - 34 lines]
> 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
Knut Stolze - 22 Mar 2005 10:23 GMT
>> Java UDFs are just like any other Java program (except that the entry
>> point
[quoted text clipped - 13 lines]
> 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/infocenter/db2v7luw/index.jsp?topic=/com.ibm.db2v7
.doc/db2a0/db2a0162.htm


Signature

Knut Stolze
Information Integration
IBM Germany / University of Jena

Rhino - 22 Mar 2005 14:19 GMT
> >> Java UDFs are just like any other Java program (except that the entry
> >> point
[quoted text clipped - 19 lines]
> 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
[quoted text clipped - 8 lines]
> The first result on google gave the V7 documentation, but you should also
> find some relevant information there:

http://publib.boulder.ibm.com/infocenter/db2v7luw/index.jsp?topic=/com.ibm.db2v7
.doc/db2a0/db2a0162.htm


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

Rhino
W Gemini - 21 Mar 2005 17:20 GMT
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.
Rhino - 21 Mar 2005 18:43 GMT
> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.