Call a Stored Procedure in HANA

Lidia picture Lidia · Apr 30, 2014 · Viewed 7.7k times · Source

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

Answer

Lidia picture Lidia · May 1, 2014

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

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

Thank you for your help @shofmn