Hi,
I'm trying to execute a Java stored proc that verifies whether a file exists or not but I'm having trouble with the OUT parameter when I try to call it from CLP:
db2 => call testFileExists()
SQL4306N Java stored procedure or user-defined function
"DB2INST1.FILE_EXISTS", specific name "SQL110816190528900" could not call Java
method "cHECKFILE", signature "(Ljava/lang/String;[". SQLSTATE=42724
However, if I change the DB2 wrapper stored proc to "IN" on the second parameter it runs! Albeit not properally working because it need to be an out parameter.
Are there any specific rules for OUT parameters concerning Java SPs?
Any ideas would be fantastic
Marc
-- DB2 9.7.2 on a Linux VM (Ubuntu Server 10.04)
CREATE PROCEDURE FILE_EXISTS (IN input CHAR(200), OUT isExists INT)
DYNAMIC RESULT SETS 0
DETERMINISTIC
LANGUAGE JAVA
PARAMETER STYLE JAVA
NO SQL
FENCED
THREADSAFE
PROGRAM TYPE SUB
EXTERNAL NAME 'FILE_EXISTS!cHECKFILE'
//FILE_EXISTS.java
import java.io.*;
public class FILE_EXISTS
{
public static void cHECKFILE (String input, int isExists) throws Exception
{
String errorMessage;
try
{
// Check file exists and pass the value back thru the OUT paramenter
File f = new File(input);
if (f.isFile()) isExists = 1;
else
isExists = 0;
}
catch (SecurityException ioe)
{
errorMessage = ioe.getMessage();
throw new IOException( errorMessage + " FAILED" );
}
}
}
-- testFileExistsSP.sql
CREATE PROCEDURE testFileExists()
BEGIN
DECLARE ISEXISTS INT DEFAULT 0;
CALL FILE_EXISTS ('/home/db2inst1/test_file.txt',ISEXISTS);
IF ISEXISTS = 1 THEN
CALL runSHCommand('echo exists > /home/db2inst1/testFileExists.txt');
ELSE
CALL runSHCommand('echo notexists > /home/db2inst1/testFileExists.txt');
END IF;
END
@