I have a query regarding PLSQL exceptions and how to handle them in Java .I have some Stored procedures which upon some exception uses “dbms_output.put_line” to print the error messages. As I can’t get these messages in my java “front-end”, How should I modify my Stored procedures to get these exceptions?
I can think about two ways but I don’t know if these are correct and if they are used in projects.
-
Use an OUT parameter to send this error message to Java, if the SP
executes successfully then it will be “null”, but in-case some
exceptions occurs I will populate this with an error message from my PLSQL EXCEPTION block. -
RAISE the exception form PLSQL Exception block so I can get the
exception using try-catch block of Java as SQLException
Maybe there is some better way which I do not know about.. Kindly suggest me how should I proceed in such situations.
TLDR :
How to code PLSQL Exception block so I can handle it in Java. The actual way used in real projects by professionals.
Better way … Follow this way .