简体   繁体   中英

Spring: JdbcTemplate throws a PLS-00201 while trying to call a stored db function

I have a function inside our oracle database named GET_ACS_SERVER_AUTH_METHOD_REP .

This is how I perform the call of the function in the database:

public String getAuthReport () throws SQLException {
        final Connection connection = jdbcTemplate.getDataSource().getConnection();

        List <SqlParameter> declaredParameters = new ArrayList <SqlParameter>();
        declaredParameters.add(new SqlParameter("start_d", Types.DATE));
        declaredParameters.add(new SqlParameter("end_d", Types.DATE));
        declaredParameters.add(new SqlOutParameter("return", Types.CLOB));

        Map <String, Object> resultMap = jdbcTemplate.call(new CallableStatementCreator() {
            @Override
            public CallableStatement createCallableStatement (Connection con) throws SQLException {
                CallableStatement callableStatement = connection.prepareCall("{call GET_SERVER_AUTH_METHOD_REP(?, ?, ?)}");
                callableStatement.setDate(1, java.sql.Date.valueOf("2016-01-01"));
                callableStatement.setDate(2, java.sql.Date.valueOf("2017-06-30"));
                callableStatement.registerOutParameter(3, Types.CLOB);
                return callableStatement;
            }
        }, declaredParameters);
        return "success";
    }

This unfortunately doesn't work and returns this error:

Caused by: java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00201: identifier 'GET_ACS_SERVER_AUTH_METHOD_REP' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

I've asked our DBA if maybe some permissions are missing on my side, but he said no.

Also I've read that there are some bugs with oracle/spring when oracle is version 12.

Maybe somebody encountered something similar and managed to fix it?

Thanks!

If this is definition of your function

create or replace FUNCTION get_server_auth_method_rep(start_d DATE, end_d DATE) return CLOB 

Code should look like this.

CallableStatement callableStatement = con.prepareCall("{? = call GET_SERVER_AUTH_METHOD_REP(?,?)}"); 
callableStatement.registerOutParameter(1, Types.CLOB);
callableStatement.setDate(2, java.sql.Date.valueOf("2016-01-01"));
callableStatement.setDate(3, java.sql.Date.valueOf("2017-06-30"));

Turned out that my DataSource bean which was passed into the constructor of the class that had the method to call the function in the database was passed with wrong db credentials. I had multiple DataSources and I had to define the correct one to be passed in by using the @Qualifier annotation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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