Question

I am trying to call a stored procedure in java from my .xsjs file. The procedure gets 2 input parameters and returns one. I can call it from an SQL console without any problem by writing:

call "MYSCHEMA"."MyPackage.procedures::addUserC50" ('name', 'lastname', ?)

This is the code in my .xsjs file, I think that it fails in the prepareCall statement. I have tried different combinations (with and without double quotation marks, with and without the name of the schema/package, with and without "(?,?,?)", with and without "{ }".... But nothing works, I always get the 500 Internal server error when I try to execute it.

Does anybody know where the error is or what is the exact syntax for the prepareCall method?

var output = 0,
    query = "";
var conn;
var cstmt;

try {

    conn = $.db.getConnection();

    query = "{ call \"MYSCHEMA\".\"MyPackage.procedures/addUserC50\"(?,?,?) }";

    cstmt = conn.prepareCall(query); // <-- Fails
    cstmt.setString(1, userName);
    cstmt.setString(2, userLastname);

    cstmt.execute();

    output = cstmt.getInteger(3);

    conn.commit(); 

    $.response.status = $.net.http.OK;
    $.response.setBody("Successfully created: " + output);

}
catch (e) {
    $.response.status = $.net.http.BAD_REQUEST;
    $.response.setBody("0");

}
finally {
    if (cstmt !== null) 
        cstmt.close();
    if (conn !== null) 
        conn.close();
}

This is the error that gives back: InternalError: dberror(Connection.prepareCall): 328 - invalid name of function or procedure: MyPackage.procedures/addUserC50: line 1 col 18 (at pos 17) at ptime/query/checker/check_call.cc:21

According to this documentation, it should be something like

var myCallableStatement = myconnection.prepareCall("{call myprocedure(?)}");

Thank you

Was it helpful?

Solution

I managed to make it run, this is the syntax that worked:

query = "call \"MyPackage.procedures::addUserC50\"(?, ?, ?)";

Thank you for your help @shofmn

OTHER TIPS

There could be different reasons why the call is failing. You can investigate your error much easier if you return the error message in the HTTP response. You can do this easily:

try {
   // Your code execution here
}
catch (e) {
   $.response.contentType = "text/html";
   $.response.setBody(e.name + ": " +  e.message));
}

If the error message doesn't help you solving the problem, paste the error message in here so that it is more easy for us to investigate as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top