Error ORA-00900 while calling a Oracle Function from Java

Viewed 540

I am getting ORA-00900 error while trying the call the Oracle function from code, whereas it works from sqldeveloper. Code from which I am trying to call the Oracle function is below.

        passwordCriteria = session.doReturningWork(connection -> {
            try (CallableStatement function = connection
                    .prepareCall("{ ? = call test$ui_mob.password_change (?,?,?,?) }")) {
                function.setEscapeProcessing(false);
                function.registerOutParameter("p_response", Types.VARCHAR);
                function.setString("p_username", "TEST_USER");
                function.setString("p_companycode", "BSH");
                function.setString("p_deviceid", "123456798");
                function.setString("p_language", "en");
                function.executeQuery();
                return function.getString(1);
            }
        });
    }

and stack trace is

Caused by: java.sql.SQLSyntaxErrorException: ORA-00900: invalid SQL statement

1 Answers

According to the JavaDoc:

The interface used to execute SQL stored procedures. The JDBC API provides a stored procedure SQL escape syntax that allows stored procedures to be called in a standard way for all RDBMSs. This escape syntax has one form that includes a result parameter and one that does not. If used, the result parameter must be registered as an OUT parameter. The other parameters can be used for input, output or both. Parameters are referred to sequentially, by number, with the first parameter being 1.

{?= call <procedure-name>[(<arg1>,<arg2>, ...)]}

{call <procedure-name>[(<arg1>,<arg2>, ...)]}

It looks like there should be no spaces between {?=, while you have spaces.

Related