gpt4 book ai didi

java - Spring:无法确定正确的调用签名 - 多个过程/函数/签名

转载 作者:行者123 更新时间:2023-11-30 06:05:00 25 4
gpt4 key购买 nike

我正在尝试从 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);
}

我得到一个异常(exception):

springframework.dao.InvalidDataAccessApiUsageException: Unable to determine the correct call signature - multiple procedures/functions/signatures

有没有办法在不要求 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)
};
}

关于java - Spring:无法确定正确的调用签名 - 多个过程/函数/签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47754891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com