Den*_* M. 5 java oracle spring stored-procedures
我正在尝试从 Oracle 存储过程获取数据。问题是在我们的数据库中有一个函数和一个过程具有相同的名称和相同的参数。
当我尝试调用它时:
@Autowired
public void setDataSource (@Qualifier("dataSource") DataSource dataSource) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.setResultsMapCaseInsensitive(true);
this.functionGetSomeCode = new SimpleJdbcCall(jdbcTemplate)
.declareParameters(new SqlOutParameter("RETURN", OracleTypes.NUMBER))
.withFunctionName("get_some_code").withSchemaName("XXX").withCatalogName("some_pkg");
}
public Integer getSomeCode (String incoming) {
SqlParameterSource incomingParameters = new MapSqlParameterSource().addValue("incoming", incoming);
return functionGetSomeCode.executeFunction(Integer.class, incomingParameters);
}
Run Code Online (Sandbox Code Playgroud)
我得到一个例外:
springframework.dao.InvalidDataAccessApiUsageException: Unable to determine the correct call signature - multiple procedures/functions/signatures
Run Code Online (Sandbox Code Playgroud)
有没有办法处理这种情况,而不要求 DBA 将函数/过程重命名为不同的名称?
我已经能够调用具有相同名称的函数和过程,但并不总是有效。在您的示例中,您似乎没有声明输入参数。尝试使用与包声明尽可能匹配的类型来声明输入和输出参数。如果仍然不起作用,您可以尝试关闭ProcedureColumnMetaDataAccess,但一定要进行测试。
这是一个例子:
protected SimpleJdbcCall buildJdbcCall(JdbcTemplate jdbcTemplate) {
SimpleJdbcCall call = new SimpleJdbcCall(jdbcTemplate)
.withSchemaName(schema)
.withCatalogName(catalog)
.withFunctionName(functionName)
// can use withProcedureName(procedureName) for procedures
//.withReturnValue()
// .withoutProcedureColumnMetaDataAccess() // may need this
.declareParameters(buildSqlParameters());
return call;
}
public SqlParameter[] buildSqlParameters() {
return new SqlParameter[]{
new SqlParameter("p_id", Types.VARCHAR),
new SqlParameter("p_office_id", Types.VARCHAR),
new SqlOutParameter("l_clob", Types.CLOB)
};
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20225 次 |
最近记录: |