Here is my pl/sql code that I am trying to execute by prepareCall
String sql = String.format(FunctionCalls.TRIGGER1);
CallableStatement callableStatement = null;
Integer result = null;
String err = null;
try {
callableStatement = connection.prepareCall(sql);
callableStatement.execute();
result = callableStatement.getInt("RES_CODE");
err = callableStatement.getString("RES_DESC" );
After executing, I want to get two of the declared parameters, RES_CODE
and RES_DESC
, but I get this error instead:
java.sql.SQLException: ORA-06550: line 2, column 1274:\nPLS-00103: Encountered the symbol \"CLOSE\" \n
After googling, many people think that the problem is in cursor that you need to declare cursors in declaration section and the process cursor after BEGIN, but I am doing аs it says. In PL/SQL Developer it works fine you can see in image.
Is it possible in java get declared parameter after execute ?
Is it possible execute TRIGER1 pl/sql code and get the two parameters RES_CODE
and RES_DESC
?
As javadoc of CallableStatement
says: "The interface used to execute SQL stored procedures."
The javadoc even shows the syntax you must use, which starts with a {
brace.
Your SQL is not a stored procedure, it is a PL/SQL block.
Also, RES_CODE
and RES_DESC
are not parameters.
What you're trying to do is entirely wrong, and if some site has shown you to do it this way, please stop using that site immediately.
Try actually creating a stored procedure with the code in question, and define actual parameters to that store procedure.
Syntax for that is:
CREATE PROCEDURE xxx ( RES_CODE OUT number, RES_DESC OUT varchar2 ) AS
variable declarations here
BEGIN
code here
END;
/
Then you call that procedure using:
String sql = "{call xxx(?,?)}";
try (CallableStatement stmt = conn.prepareCall(sql)) {
stmt.registerOutParameter(1, TYPES.INTEGER);
stmt.registerOutParameter(2, TYPES.VARCHAR);
stmt.execute();
result = stmt.getInt(1);
err = stmt.getString(2);
}