Search code examples
javaoracle-databasestored-proceduresjdbccallable-statement

Error when calling an Oracle stored procedure though Java code


I am calling a PL/SQL procedure in a Java application to update a database entry.

Connection connection = null;
CallableStatement preparedCall = null;
Integer result = 0;
preparedCall = connection.prepareCall("{ call ? := pkg_temp.update_data(?, ?)}");
preparedCall.registerOutParameter(1, OracleTypes.INTEGER);
preparedCall.setString(2, variable1);
preparedCall.setString(3, cariable2);
result = preparedCall.executeUpdate();

But I am getting the below error at executeUpdate()

Caused by: java.sql.SQLException: ORA-06550: line 1, column 11:
PLS-00103: Encountered the symbol "=" when expecting one of the following:
:= . ( @ % ; indicator
ORA-06550: line 1, column 51:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
. ( ) , * % & - + / at mod remainder rem <an exponent (**)>
and or || multiset

Where am I doing wrong?


Solution

  • The := is wrong and the placeholder for return parameter must be listed before the call keyword (as documented in the JavaDocs):

    connection.prepareCall("{?= call pkg_temp.update_data(?, ?)}");