Here’s a sample Java class that I wrote
public class Sleeper {
public static void Sleep(int seconds){
try {
Thread.sleep(seconds * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
and I wish to call this as a stored procedure this way :
DROP PROCEDURE DEM.SLEEPUTIL@
-- echo "ETAPE 2 DE 3 > Suppression puis instllation du JAR";
CALL SQLJ.REMOVE_JAR('DEM.SLEEPER_JAR')@
CALL SQLJ.REFRESH_CLASSES()@
CALL SQLJ.INSTALL_JAR("file:///Sleeper.jar",'DEM.SLEEPER_JAR',0)@
CALL SQLJ.REFRESH_CLASSES()@
-- echo "ETAPE 2 DE 3 > CREATION DE LA PROCEDURE ";
CREATE PROCEDURE DEM.SLEEPUTIL (IN NUM INTEGER)
COMMIT ON RETURN NO
SPECIFIC SLEEPUTIL
DYNAMIC RESULT SETS 0
DETERMINISTIC
LANGUAGE JAVA
PARAMETER STYLE JAVA
NO DBINFO
FENCED
THREADSAFE
NO SQL
PROGRAM TYPE SUB
EXTERNAL NAME 'DEM.SLEEPER_JAR:com.desj.visa.db.procedures.Sleeper!Sleep'
And I’m repeatedly getting this error:
14:54:00 [CALL - 0 row(s), 0.032 secs] [Error Code: -4304, SQL State: 42724] DB2 SQL Error: SQLCODE=-4304, SQLSTATE=42724, SQLERRMC=DEM.SLEEPUTIL;SLEEPUTIL;/db2/db2d095/sqllib/function/jar/DEM/SLEEPER_J, DRIVER=4.3.85
CALL DEM.SLEEPUTIL(3);
... 1 statement(s) executed, 0 row(s) affected, exec/fetch time: 0.032/0.000 sec [0 successful, 0 warnings, 1 errors]
What is wrong with this?
I found It.
The problem was related to the Java version installed on the server.
The server has Java 1.5 and the code I deployed to was compiled in 1.6.
So I recompiled everything to 1.5 and deployed it.
Everything works fine now so you guys have a good example on how to deploy a Java stored procedure on DB2.
Cheers.