【问题标题】:Unable to determine the correct call signature for {procedure name} - package name should be specified separately using '.withCatalogName("PARAMS")'无法确定 {procedure name} 的正确调用签名 - 应使用 '.withCatalogName("PARAMS")' 单独指定包名称
【发布时间】:2020-04-25 14:36:23
【问题描述】:

我有 java 代码来执行存储过程,如下所示:

@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {SQLException.class, Exception.class })
public void executeSPForInsertData(DataSource ds,String procedureName,Map<String, Object> inputParameter){
    //PARAMS.PKG_PARA_UPLD_VAL.PR_SP_FAHMI
    String[] inParam = inputParameter.keySet().toArray(new String[0]);
    SqlParameterSource in = new MapSqlParameterSource().addValue("P_T_TABLE_UPLD_EXCEL",inputParameter);

    SimpleJdbcCall jdbcCall = new SimpleJdbcCall(paramsDataSourceBean)
                              .withProcedureName(procedureName);

    String[] path = procedureName.split(".");
    if (path.length >= 2) {
        jdbcCall.withSchemaName(path[0]);
        jdbcCall.withCatalogName(path[1]);
        jdbcCall.withProcedureName(path[2]);
    }
    Map<String,Object> outputParameter = jdbcCall.execute(in);
}

运行时出现这个错误

org.springframework.dao.InvalidDataAccessApiUsageException: Unable to determine the correct call signature for PARAMS.PKG_PARA_UPLD_VAL.PR_SP_FAHMI - package name should be specified separately using '.withCatalogName("PARAMS")'

【问题讨论】:

  • 程序是否在一个包中?
  • 是的,程序在一个包中。

标签: java sql jdbc procedure spring-jdbc


【解决方案1】:

这对我有用(Spring 5.x、Java 8、Oracle DB)

假设您在包 PKG1 中有一个名为 MY_PROC 的存储过程

//Consturct SqlParameter/SqlOutParameter
List<SqlParameter> parameters = new ArrayList<>();
parameters.add(new SqlParameter("param_x", Types.VARCHAR));
// ...add all the required SqlParameter here(optional params can be skipped if you wish) .
// SqlOutParameter, SqlInOutParameter can also be added here as per your requirement

// Construct the SimpleJdbcCall
final SimpleJdbcCall call =
    new SimpleJdbcCall(jdbcUtil.getJdbcTemplate()).withCatalogName("PKG1")
    .withProcedureName("MY_PROC")
    //.withSchemaName("YOUR_SCHEME_NAME")
    .withoutProcedureColumnMetaDataAccess()
    .withNamedBinding()
    .declareParameters(parameters.stream().toArray(SqlParameter[]::new));


// ConstructParameterSource
final MapSqlParameterSource paramSource = new MapSqlParameterSource();
paramSource.addValue("param_x", "value");
// ...add all the required named param values here

Map<String, Object> result = call.execute(paramSource);

【讨论】:

    猜你喜欢
    • 2018-05-25
    • 2013-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    相关资源
    最近更新 更多