If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Can't load java class of Java UDF

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-18-07, 09:35
skchonghk skchonghk is offline
Registered User
 
Join Date: Jan 2007
Posts: 5
Can't load java class of Java UDF

Dear all smart experts,

I write a simple Java UDF, which should run on DB2 v8 on AIX. But it can't load the Java class. Help ugently needed!! Thanks!

I develop and deploy the Java UDF with these steps:

1. Write the java class, compile and make a jar (see below for source).
2. Call SQLJ.REPLACE_JAR ('file:/home/pws01ta/pws01ta1/examples.jar','test',0)
3. call sqlj.refresh_classes()
4. Create the function by running "create function properties() returns table (property varchar(500), value varchar(500)) external name 'test:com.hase.JVMProperties!dump' language java parameter style db2general fenced no sql disallow parallel scratchpad"


Everything seems ok but when I run the SQL "select * from table (properties()) as t", I got:

SQL4304N Java stored procedure or user-defined function "PWS01TA1.PROPERTIES",
specific name "SQL070118203908600" could not load Java class
"com/hase/JVMProperties", reason code "1". SQLSTATE=42724


This is the source code of the java class:

package com.hase;

import COM.ibm.db2.app.*;
import java.util.*;

public class JVMProperties extends UDF {
Enumeration propertyNames;
Properties properties ;

public void dump (String property, String value) throws Exception
{
int callType = getCallType();
switch(callType) {
case SQLUDF_TF_FIRST:
break;
case SQLUDF_TF_OPEN:
properties = System.getProperties();
propertyNames = properties.propertyNames();
break;
case SQLUDF_TF_FETCH:
if (propertyNames.hasMoreElements()) {
property = (String) propertyNames.nextElement();
value = properties.getProperty(property);
set(1, property);
set(2, value);
} else {
setSQLstate("02000");
}
break;
case SQLUDF_TF_CLOSE:
break;
case SQLUDF_TF_FINAL:
break;
default:
throw new Exception("UNEXPECT call type of "+callType);
}
}
}
Reply With Quote
  #2 (permalink)  
Old 01-18-07, 13:00
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Argument lists of your UDF and the Java method don't match - I think that might be the reason.
Reply With Quote
  #3 (permalink)  
Old 01-18-07, 21:07
skchonghk skchonghk is offline
Registered User
 
Join Date: Jan 2007
Posts: 5
The parameters to dump method are not input parameters of the functions...

I tried the samples UDFsqlsv.java from IBM. It does not work too.
Reply With Quote
  #4 (permalink)  
Old 01-19-07, 03:43
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
The parameters are fine. What do you have in the diag.log for the function call? There will be some additional information.

Have you tried the same things without JAR files?
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On