473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Do I observe the DB2GENERAL calling convention in my Java UDF?


If I create the function HELLO in schema S01 as follows,

@
CREATE FUNCTION S01.HELLO()
RETURNS VARCHAR(32)
EXTERNAL NAME 'UDFSRVXYZ!sayHelloWorld'
LANGUAGE JAVA
PARAMETER STYLE DB2GENERAL
NO SQL
DETERMINISTIC
NOT FENCED
SCRATCHPAD
NO EXTERNAL ACTION
@

then I can implement it as shown here?

// Default package
public
class UDFSRVXYZ
extends
COM.ibm.db2.app.UDF
{
public
void sayHelloWorld()
throws
Exception
{
set(1, "Hello, World!" );
}
}

I tried hard, but I could not get it to work.
What I already took care about:

(1) Deploy class file to the FUNCTION directory of the instance. In my
case that is C:\Programme\IBM\SQLLIB\FUNCTION\ on the server machine.
(2) issue the CREATE FUNCTION statement as shown above
(3) CALL SQLJ.REFRESH_CLASSES()
(4) I do have EXECUTE permission on S01.HELLO
Then I wanted to reap the results:

SELECT S01.HELLO(), value FROM S01.HELLOTABLE FETCH FIRST 3 ROWS ONLY

But that resulted in DB2 complaining, and not executing the Java method
I wanted it to execute:

SQL4306N In Java gespeicherte Prozedur oder benutzerdefinierte
Funktion
"S01.HELLO", spezifischer Name "SQL050928105824200" kann die
Java-Methode
"sayHelloWorld", Kennung "(Ljava/lang/String;)V" nicht aufrufen.
SQLSTATE=42724

So now, which part of the manual did I neglect to pay attention to? I
think I did observe the calling convention for DB2GENERAL. Another
question would be what the Java method should look like with parameter
style JAVA?

Any help much appreciated, Claus

----

A complete transcript is enclosed so you can see exactly what I did:

------------------------------ Eingegebene Befehle
---------------------------

DROP FUNCTION S01.HELLO
@
CREATE FUNCTION S01.HELLO()
RETURNS VARCHAR(32)
EXTERNAL NAME 'UDFSRVXYZ!sayHelloWorld'
LANGUAGE JAVA
PARAMETER STYLE DB2GENERAL
NO SQL
DETERMINISTIC
NOT FENCED
SCRATCHPAD
NO EXTERNAL ACTION
@
CALL SQLJ.REFRESH_CLASSES()
@
DROP TABLE S01.HELLOTABLE
@
CREATE TABLE S01.HELLOTABLE ( value INTEGER )
@
INSERT INTO S01.HELLOTABLE ( value ) VALUES ( 1 )
@
INSERT INTO S01.HELLOTABLE ( value ) VALUES ( 2 )
@
INSERT INTO S01.HELLOTABLE ( value ) VALUES ( 3 )
@
SELECT value FROM S01.HELLOTABLE
FETCH FIRST 3 ROWS ONLY
@
SELECT S01.HELLO(), value FROM S01.HELLOTABLE
FETCH FIRST 3 ROWS ONLY
@
------------------------------------------------------------------------------
DROP FUNCTION S01.HELLO
DB20000I Der Befehl SQL wurde erfolgreich ausgeführt.

CREATE FUNCTION S01.HELLO()
RETURNS VARCHAR(32)
EXTERNAL NAME 'UDFSRVXYZ!sayHelloWorld'
LANGUAGE JAVA
PARAMETER STYLE DB2GENERAL
NO SQL
DETERMINISTIC
NOT FENCED
SCRATCHPAD
NO EXTERNAL ACTION

DB20000I Der Befehl SQL wurde erfolgreich ausgeführt.

CALL SQLJ.REFRESH_CLASSES()
DB20000I Der Befehl CALL wurde erfolgreich ausgeführt.
DROP TABLE S01.HELLOTABLE
DB20000I Der Befehl SQL wurde erfolgreich ausgeführt.

CREATE TABLE S01.HELLOTABLE ( value INTEGER )
DB20000I Der Befehl SQL wurde erfolgreich ausgeführt.

INSERT INTO S01.HELLOTABLE ( value ) VALUES ( 1 )
DB20000I Der Befehl SQL wurde erfolgreich ausgeführt.

INSERT INTO S01.HELLOTABLE ( value ) VALUES ( 2 )
DB20000I Der Befehl SQL wurde erfolgreich ausgeführt.

INSERT INTO S01.HELLOTABLE ( value ) VALUES ( 3 )
DB20000I Der Befehl SQL wurde erfolgreich ausgeführt.

SELECT value FROM S01.HELLOTABLE FETCH FIRST 3 ROWS ONLY

VALUE
-----------
1
2
3

3 Satz/Sätze ausgewählt.
SELECT S01.HELLO(), value FROM S01.HELLOTABLE FETCH FIRST 3 ROWS ONLY

1 VALUE
-------------------------------- -----------
SQL4306N In Java gespeicherte Prozedur oder benutzerdefinierte
Funktion
"S01.HELLO", spezifischer Name "SQL050928110204800" kann die
Java-Methode
"sayHelloWorld", Kennung "(Ljava/lang/String;)V" nicht aufrufen.
SQLSTATE=42724

SQL4306N In Java gespeicherte Prozedur oder benutzerdefinierte
Funktion "S01.HELLO", spezifischer Name "SQL050928110204800" kann die
Java-Methode "sayHelloWorld", Kennung "(Ljava/lang/String;)V "
nicht aufrufen.

Erklärung:

Die mit der Klausel EXTERNAL NAME einer Anweisung CREATE
PROCEDURE oder CREATE FUNCTION bezeichnete Java-Methode konnte
nicht gefunden werden. Die deklarierte Argumentenliste stimmt
möglicherweise nicht mit den von der Datenbank erwarteten Angaben
überein, oder das Exemplar verfügt nicht über eine allgemein
bekannte ("public") Methode.

Benutzeraktion:

Stellen Sie sicher, dass für das Exemplar die Java-Methode als
allgemein bekannt ("public") deklariert ist und die erforderliche
Argumentenliste für den Aufruf zur Verfügung steht.

sqlcode : -4306

sqlstate : 42724

----

Nov 12 '05 #1
5 2539
Is it possible to extract a candidate Java method signature from what's
in the SYSCAT.FUNC*-Tables? Anyone done that already, ie anyone has
already written a UDF that will spit out a matching method signature in
return for schema name and function name?

What is SYSPROC.GET_ROUTINE_OPTS() about?

Nov 12 '05 #2
cl*********@abraxas.ch wrote:
Is it possible to extract a candidate Java method signature from what's
in the SYSCAT.FUNC*-Tables? Anyone done that already, ie anyone has
already written a UDF that will spit out a matching method signature in
return for schema name and function name?

What is SYSPROC.GET_ROUTINE_OPTS() about?

It's... SET_ROUTINE_OPTS() best friend.... ;-)
The routine options are used to set the PREP options for _SQL_ Procedures.
Common settings are: 'BLOCKING ALL' or 'EXPLAIN ALL'

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #3
I see. And what about my original post?

Nov 12 '05 #4
Hello.

You have to do this:
public void sayHelloWorld(String result)
instead of:
public void sayHelloWorld()

and don't use this clauses in the function definition:
NOT FENCED
SCRATCHPAD

Sincerely,
Mark B.

Nov 12 '05 #5
ÑпоÑиба.

Adding the String argument to the method signature solved the problem,
thank you.

For the rest of you that might be interested:

* Specifying SCRATCHPAD or not had no influence on whether or not the
function is called correctly. But it is advantageous not to specify
SCRATCHPAD for this UDF, as it doesn't need to use a scratchpad.

* Specifying NOT FENCED works -- if only you deploy the code into the
proper subdirectory, as specified in the manuals. Thanks Mark, I
overlooked that, looking at it so many times.

Kind regards, Claus

Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jeremy R. Harner | last post by:
I'm trying to use a DLL, but when I try to run it from Visual Basic by going to Run > Start I get a 'Bad DLL Calling Convention' error when I try to access a function inside the DLL. If I compile...
1
by: Asapi | last post by:
1. Are linkage convention and calling convention referring to the same thing? 2. Does calling convention differ between languages C and C++? 3. How does calling convention differ between...
8
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int...
1
by: Leftie | last post by:
Folks, I'm trying to call an unmanaged function from VB.NET and keep getting "Object reference not set to an instance of an object" error. The code that i wrote can be found at:...
2
by: Geler | last post by:
A theoretical question: Sorry if its a beginner question. Here is a quote from the MSDN explaning the C/C++ calling convention.. It demonstrates that the calling function is responsible to clean...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
0
by: Nova | last post by:
Hi, I created a Java UDF (PARAMETER STYLE JAVA) for DB2 9 Express-C. I finally does what I want it to do. However, after a few hundred calls to the UDF, it fails and raises an SQL error,...
10
by: sulekhasweety | last post by:
Hi, the following is the definition for calling convention ,which I have seen in a text book, can anyone give a more detailed explanation in terms of ANSI - C "the requirements that a...
16
by: Jaco Naude | last post by:
Hi there, This is my first post over here and I hope someone can give me some guidance. I'm trying to embed Python into a Visual C++ 2008 application and I'm getting linker problems. I've...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.