Link to home
Start Free TrialLog in
Avatar of Enuda
Enuda

asked on

UDF unable to load Java class. What do I need to do to make this work?

Hello all,
Continuing my UDF adventure started two days ago, I have managed to get the UDF registered but having problem getting the Java code to work. I need assistance to get this Double Metaphone Java UDF to work pretty quickly. Here is what I tried to run and the error message that resulted:
                SQL
select nm_frst, NM_LST, DB2ADMIN.DMPHONEJAVASCALAR(NM_LST)
from FSNST201.BR_DOH_BIRTH_RECORD
WHERE NM_FRST = 'SKYLER';

SQL4304N  Java stored procedure or user-defined function "DB2ADMIN.DMPHONEJAVASCALAR", specific name "DMPHONEJAVASCALAR" could not load Java class "/home/db2inst1/sqllib/fun", reason code "".  SQLSTATE=42724

SQL4304N  Java stored procedure or user-defined function "DB2ADMIN.DMPHONEJAVASCALAR", specific name "DMPHONEJAVASCALAR" could not load Java class "/home/db2inst1/sqllib/fun", reason code "".

Explanation:
The Java class given by the EXTERNAL NAME clause of a CREATE PROCEDURE or CREATE FUNCTION statement could not be loaded. The reason codes are:
 
 1 The class was not found on the CLASSPATH.  

 2 The class did not implement the required interface ("COM.ibm.db2.app.StoredProc" or  "COM.ibm.db2.app.UDF") or lacked the Java "public" access flag.  

 3 The default constructor failed or was unavailable.  

 4 Could not load driver for "jdbc:default:connection".  

 5 Could not establish default context.  

User Response:

Ensure that the compiled ".class" file is installed in the CLASSPATH, for example under "sqllib/function".  Ensure it implements the required Java interfaces and is "public".  
sqlcode :  -4304
sqlstate : 42724
SQLCODE: -4304

I will appreciate it if someone can guide me to determine if at all I am properly set up to invoke a javaUDF, what do I need to look for, and how I can go about setting up my environment and the UDF to execute successfully.
I fyou any question that you need answered please do not hesitate to ask as I will be monitoring this forum for the best part of this evening.

Thanks

Enuda
   
SOLUTION
Avatar of momi_sabag
momi_sabag
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Enuda
Enuda

ASKER

Momi_sabq,
Thanks for your response. I'm sure I will be reading more of java docs in the future. Right now I find myself in a position of doing it first, and learn later!
(1) Yes, db2inst1 runs the instance. First, the CLASSPATH. I tried to find it using the command "Which java" and got  "/usr/bin/java" which is supposed to be my java home. Is this the same as CLASSPATH?
When I looked in this directory, I found this "java ---->/etc/alternatives/java". So I navigated to this path, found and once again I found this "java -> /usr/lib/jvm/jre-1.4.2-gcj/bin/java". Once again, I navigated to this directory and found two scripts named "java"  and "rmiregistry". I browsed the member called java and found this in the script the following lines that was of interest:

        params="-Djava.home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre $params"
        clp="$CLASSPATH:/usr/share/java/libgcj-$GCC.jar"  

The above seem to point to the real classpath, right? How can I be sure of this? As I said, there are only the two members above in this dirctory. Nothing else. I have attached the actual java code as I have it. Please take a look.

problem is just coping the jar files / class files of your java code to the jdbc driver directory, because it is in the CLASSPATH. the jdbc driver under AIX if i'm not mistaken will be
/home/db2inst1/sqllib/java

On error item #2, how can I find out if a class did or did not implement the required interface ("COM.ibm.db2.app.StoredProc" or  "COM.ibm.db2.app.UDF") or lacked the Java "public" access flag.?
Is there any config or init file that I can look into to find out? Any environment variable?

 3 The default constructor failed or was unavailable.  What is this? How can I tell if it is available? Is this a system code or microcode of some sort?

 4 Could not load driver for "jdbc:default:connection".  Now, drivers I can understand but don't know how to find out if it is available and loaded at startup. Anyway to find out?

 5 Could not establish default context. What could this be or mean?

momi_sabaq, I trully appreciate your continuing effort to help with this problem.
Thanks




-------  Begining of Java in Script ------
exec $COMMAND
chmod +x $COMMAND
echo "exec /usr/bin/gij $params" >>$COMMAND
echo "rm $COMMAND" >$COMMAND
COMMAND=`mktemp /tmp/javaXXXXXX`
export CLASSPATH="$clp"
fi
        clp="$clp:/usr/share/java/libgcj-$GCC.jar"
        # We NEED this
if ! echo $clp |grep -q /usr/share/java/libgcj-$GCC.jar; then
 
fi
    params="-Djava.version=1.4.2 $params"
if [ -z "$HAVE_JAVA_VERSION" ]; then
 
fi
    params="-Djava.home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre $params"
if [ -z "$HAVE_JAVA_HOME" ]; then
 
done
        shift
        fi
                fi
                        HAVE_APPNAME=yes
                        params="$params \"`echo $1 |sed -e 's,",\\\\",g;s,/,.,g'`\""
                else
                        params="$params \"`echo $1 |sed -e 's,",\\\\",g'`\""
                if [ -n "$HAVE_APPNAME" ]; then
        else
                echo "Warning: $1 not understood. Ignoring." >&2
                # Yuck. Unknown parameter. Let's pretend nothing happened.
        elif [ -z "$HAVE_APPNAME" -a "`echo $1 |cut -b1`" = "-" ]; then
                params="$params \"`echo $1 |sed -e 's,",\\\\",g'`\""
                fi
                    HAVE_JAVA_VERSION=yes
                elif [ "`echo $1 |cut -b1-15`" = "-Djava.version=" ]; then
                    HAVE_JAVA_HOME=yes
                elif [ "`echo $1 |cut -b1-12`" = "-Djava.home=" ]; then
                        export LD_LIBRARY_PATH=`echo $1 |cut -b21-`:$LD_LIBRARY_PATH
                if [ "`echo $1 |cut -b1-20`" = "-Djava.library.path=" ]; then
        elif [ "`echo $1 |cut -b1-2`" = "-D" ]; then
                clp="`echo $1 | sed \"s~.*/lib/rt.jar~/usr/share/java/libgcj-$GCC.jar~\"`"
                        params="$params \"`echo $1 |sed -e 's,",\\\\",g;s,/,.,g'`\""
                else
                        params="$params \"`echo $1 |sed -e 's,",\\\\",g'`\""
                if [ -n "$HAVE_APPNAME" ]; then
        else
                echo "Warning: $1 not understood. Ignoring." >&2
                # Yuck. Unknown parameter. Let's pretend nothing happened.
        elif [ -z "$HAVE_APPNAME" -a "`echo $1 |cut -b1`" = "-" ]; then
                params="$params \"`echo $1 |sed -e 's,",\\\\",g'`\""
                fi
                    HAVE_JAVA_VERSION=yes
                elif [ "`echo $1 |cut -b1-15`" = "-Djava.version=" ]; then
                    HAVE_JAVA_HOME=yes
                elif [ "`echo $1 |cut -b1-12`" = "-Djava.home=" ]; then
                        export LD_LIBRARY_PATH=`echo $1 |cut -b21-`:$LD_LIBRARY_PATH
                if [ "`echo $1 |cut -b1-20`" = "-Djava.library.path=" ]; then
        elif [ "`echo $1 |cut -b1-2`" = "-D" ]; then
                clp="`echo $1 | sed \"s~.*/lib/rt.jar~/usr/share/java/libgcj-$GCC.jar~\"`"
                shift
        elif [ "$1" = "-classpath" -o "$1" = "-cp" ]; then
                gcj --version 1>&2
                echo 'java version "1.4.2"' 1>&2
        elif [ "$1" = "-showversion" ]; then
                exit 0
                echo 'java full version "gcj-1.4.2"' 1>&2
        elif [ "$1" = "-fullversion" ]; then
                exit 0
                gcj --version 1>&2
                echo 'java version "1.4.2"' 1>&2
        if [ "$1" = "-version" ]; then
while [ "$#" != 0 ]; do
unset HAVE_APPNAME || :
fi
        clp="/usr/share/java/libgcj-$GCC.jar"
else
        clp="$CLASSPATH:/usr/share/java/libgcj-$GCC.jar"
if [ -n "$CLASSPATH" ]; then
GCC=`gcj --version |head -n1 |awk '{ print $3; }'`
# (c) 2002-2003 Bernhard Rosenkraenzer <bero@arklinux.org>
# Emulate the jdk java command using gcj
#!/bin/sh

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial