简体   繁体   English

从Java调用存储过程-ORA错误未引发异常

[英]Calling a Stored Procedure from Java - Exception not thrown on ORA error

I'm calling an Oracle Stored Procedure from Java, and have no problem sending input parameter values and getting the output parameter values back to Java once I execute the CallableStatement . 我正在从Java调用Oracle存储过程,一旦执行CallableStatement ,就可以发送输入参数值并将输出参数值返回给Java。

However, when i send some bad data into the Stored Procedure (to force an error) and execute the CallableStatement 's execute method, I'd expect a SQLException to be thrown in my method. 但是,当我向存储过程中发送一些不良数据(以强制执行错误)并执行CallableStatementexecute方法时,我希望在我的方法中抛出SQLException This doesn't happen, and the code continues as normal. 这不会发生,并且代码照常继续。

When I run the Stored Procedure through SQL Developer, i can clearly see an oracle error message (code ORA-06502 ) displayed in the Log window. 通过SQL Developer运行存储过程时,我可以清楚地看到在“日志”窗口中显示的oracle错误消息(代码ORA-06502 )。 So it's a mystery to me why my Java code isn't catching any error message. 因此,为什么我的Java代码没有捕获任何错误消息对我来说还是一个谜。

Does anyone have an idea what the source of this behaviour is? 有谁知道这种行为的根源是什么? Is the Stored Procedure not throwing the error correctly; 存储过程没有正确引发错误吗? is the Java try/catch not recognizing the exception thrown? Java try/catch无法识别抛出的异常? Unfortunately i have no access to the Stored Proc code to check how they're handling errors. 不幸的是,我无权访问Stored Proc代码来检查它们如何处理错误。

Any pointers are appreciated. 任何指针表示赞赏。

Java doesn't throw SQLException because the call stored procedure Java function (CallableStatement) has successfully sent the command to Oracle. Java不会引发SQLException,因为调用存储过程Java函数(CallableStatement)已成功将命令发送给Oracle。 If this procedure is executed with success, the methode of CallableStatement give us 0, otherwise different of 0, so you don't see SQLException. 如果成功执行了此过程,则CallableStatement的方法将给我们0,否则为0,因此您不会看到SQLException。

But in case of SQLDevelopper, It's a true interpreter SQL for Oracle, so you can see the SQLException. 但是对于SQLDevelopper来说,这是一个真正的Oracle解释器SQL,因此您可以看到SQLException。

Exception is thrown only when your first executable statement fails in stored procedure. 仅当您的第一个可执行语句在存储过程中失败时,才会引发异常。 If at lest one statement executes correctly except the first one exception won't be thrown. 如果至少一个语句正确执行,则不会抛出第一个异常。

You can try putting transaction in stored procedure itself and catch exception if any statement fails and throw an exception from catch block. 您可以尝试将事务放入存储过程本身,如果任何语句失败,则捕获异常,并从catch块引发异常。 All of this in stored procedure. 所有这些都在存储过程中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM