[英]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
. 我的Oracle数据库中有一个名为
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. 我问过我们的DBA,也许我这边缺少一些权限,但是他说不。
Also I've read that there are some bugs with oracle/spring when oracle is version 12. 我也读到,当oracle是12版时,oracle / spring有一些错误。
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. 原来,我的
DataSource
bean是通过错误的db凭据传递的,该DataSource
bean传递到了具有在数据库中调用该函数的方法的类的构造函数中。 I had multiple DataSources and I had to define the correct one to be passed in by using the @Qualifier
annotation. 我有多个数据源,必须使用
@Qualifier
批注定义正确的数据源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.