【问题标题】:Issues while calling Oracle stored procedure with CLOB type input parameter from java JDBCTemplate从 java JDBCTemplate 调用具有 CLOB 类型输入参数的 Oracle 存储过程时出现问题
【发布时间】:2019-09-28 13:12:05
【问题描述】:

我在 Sring 启动中使用 JDBCtemplate 功能并尝试调用具有 CLOB 类型输入参数的 oracle 存储过程。我使用 LobHandler 将输入字符串转换为 Clob,但我收到错误为“Caused by: java.sql.SQLException: ORA-22922: nonexistent LOB value”

Below is the sample code:

@Override
    public Map<String, Object> getNewRequestFids(String cisarResponse){
        Map<String, Object> resultMap = new HashMap<String,Object>();
        LobHandler lobHandler = new DefaultLobHandler();

        SimpleJdbcCall executor = new SimpleJdbcCall(jdbcTemplate).withProcedureName("CA_FID.GETREQUESTFIDS")
                .withoutProcedureColumnMetaDataAccess();
        executor.addDeclaredParameter(new SqlParameter("P_FIDLIST", Types.CLOB));
        executor.addDeclaredParameter(new SqlOutParameter("P_RESULT", OracleTypes.CURSOR, new FidExtractor()));

        executor.compile();
        SqlParameterSource params = new MapSqlParameterSource().addValue("P_FIDLIST", new SqlLobValue(cisarResponse, lobHandler));

        resultMap = executor.execute(params);
        System.out.println("The resultMap is: " + resultMap);

return resultMap;
}

Input to this function is like "finalJsonString.toString" where finalJsonString is "{"items":[{"id":7849081,"username":"marcinTest","description":"TEST DESCRIPTION","privileged":true,"critical":true,"system":{"id":4648,"systemName":"CBDEMLA1","description":"WPB - DEV","environment":"Production","type":"MIDRANGE","platform":null,"platformDetails":null,"sourceSystemId":null,"hostName":"CBDEMLA1","databaseAttributes":null},"owner":{"id":1010132677,"firstName":"MICHAL","lastName":"KOSTRZEWSKI","soeId":"MK32677"}}]}"

【问题讨论】:

    标签: spring-boot jdbctemplate


    【解决方案1】:

    我正在使用SqlLobValue 关注您的代码。我解决了将Clob 数据插入Oracle 11G 数据库的问题。
    我的错误是ORA-22922: nonexistent LOB value

    
    jdbcTemplate.setResultsMapCaseInsensitive(true);
    simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate).withCatalogName(FIDProcedures.PKG_FID);
    simpleJdbcCall.withProcedureName(FIDProcedures.FID_LOG_UPDATE).declareParameters(
            new SqlParameter("P_LOG_ID", Types.NUMERIC), new SqlParameter("P_REQUEST", Types.CLOB),
            new SqlParameter("P_RESPONSE", Types.CLOB), new SqlParameter("P_ERROR_EXCEPTION", Types.CLOB),
            new SqlParameter("P_ENGINE_ELAPSE", Types.VARCHAR),
            new SqlParameter("P_STATUS", Types.VARCHAR));
    
    Map<String, Object> paramaters = new HashMap<String, Object>();
    paramaters.put("P_LOG_ID", logId);
    paramaters.put("P_REQUEST", new SqlLobValue(request));
    paramaters.put("P_RESPONSE", new SqlLobValue(response));
    paramaters.put("P_ERROR_EXCEPTION", new SqlLobValue(error));
    paramaters.put("P_ENGINE_ELAPSE", String.valueOf(elapse));
    paramaters.put("P_STATUS", status);
    
    simpleJdbcCall.execute(paramaters);
    

    希望上面的代码能帮到你!

    【讨论】:

      猜你喜欢
      • 2012-03-02
      • 1970-01-01
      • 2021-03-02
      • 1970-01-01
      • 2021-11-16
      • 2019-02-14
      • 1970-01-01
      • 2020-09-27
      • 1970-01-01
      相关资源
      最近更新 更多