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 > Create method(external scalar) in Java

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-24-03, 10:13
MoeliTec MoeliTec is offline
Registered User
 
Join Date: Nov 2003
Location: Belgium
Posts: 12
Create method(external scalar) in Java

I'm using DB2 V8, jdk1.3.1

I have following java-code

import COM.ibm.db2.app.*;
import java.io.*;
import java.sql.SQLException;

public class udfs extends UDF
{
public void methmul(String in, int a,int b) throws IOException
{
try
{
FileWriter out2 = new FileWriter("c:\\db2\\errorsudf.log");
out2.write("In method methmul");
out2.close();
set(3,a * 4);
}
catch(Exception e)
{
FileWriter out = new FileWriter("c:\\db2\\errorsudf.log");
e.printStackTrace(new PrintWriter(out));
out.close();
}
}
}

and following SQL code

CREATE TYPE AddressType AS (street Varchar(30), number Integer, zip Char(10), city Varchar(20)) FINAL MODE DB2SQL;

CREATE FUNCTION giveAllf(addr AddressType) RETURNS Varchar(100) RETURN SELF..street || ' ' || CAST(SELF..number AS CHAR(5)) || ', ' || SELF..zip || ' '||SELF..city;

CREATE FUNCTION fillf(Str Varchar(30), num Integer, zip varchar(10), cit Varchar(20)) RETURNS AddressType RETURN AddressType()..street(str)..number(num)..zip(CAST (zip AS Char(10)))..city(cit);

%CREATE TRANSFORM FOR AddressType db2_program (FROM SQL WITH FUNCTION giveAllf( AddressType), TO SQL WITH FUNCTION fillf( Varchar(30), Integer, varchar(10), Varchar(20)));

ALTER TYPE AddressType ADD METHOD test(a int) RETURNS int LANGUAGE java PARAMETER STYLE DB2GENERAL;

CREATE METHOD test(a int) FOR AddressType EXTERNAL NAME 'udfs.methmul' TRANSFORM GROUP db2_program;

Now I want to test this method:

SELECT AddressType()..test(3) FROM testTable;

I get following error

SQL0901N The SQL statement failed because of a non-severe system error. Subsequent SQL statements can be processed. (Reason "Unknown function
protocol".) SQLSTATE=58004

Anyone an idea?
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