在HANA中调用存储过程(Call a Stored Procedure in HANA)

系统教程 行业动态 更新时间:2024-06-14 16:59:46
在HANA中调用存储过程(Call a Stored Procedure in HANA)

我试图从我的.xsjs文件中调用java中的存储过程。 该过程获得2个输入参数并返回一个。 我可以通过编写来从SQL控制台调用它而没有任何问题:

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

这是我的.xsjs文件中的代码,我认为它在prepareCall语句中失败了。 我尝试了不同的组合(有和没有双引号,有和没有架构/包的名称,有和没有“(?,?,?)”,有和没有“{}”....但没有工作,当我尝试执行它时,我总是得到500内部服务器错误。

有人知道错误的位置或prepareCall方法的确切语法是什么?

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(); }

这是给出的错误:InternalError:dberror(Connection.prepareCall):328 - 函数或过程的名称无效:MyPackage.procedures / addUserC50:第1行第18行(位于第17位)ptime / query / checker / check_call。 CC:21

根据这个文档 ,它应该是这样的

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

谢谢

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

最满意答案

我设法让它运行,这是有效的语法:

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

谢谢你的帮助@shofmn

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

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

Thank you for your help @shofmn

更多推荐

本文发布于:2023-04-17 08:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/280d1102631b379d6a0c38f3a31a376d.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:存储过程   HANA   Call   Procedure   Stored

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!