从Java JDBCTemplate用CLOB类型输入参数调用Oracle存储过程时出现问题

时间:2019-05-10 15:34:52

标签: spring-boot jdbctemplate

我在Sring引导中使用JDBCtemplate功能,并尝试调用具有CLOB类型输入参数的oracle存储过程。我已经使用LobHandler将输入字符串转换为Clob,但是由于出现“由于:java.sql.SQLException:ORA-22922:不存在的LOB值”而出现错误

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"}}]}"

1 个答案:

答案 0 :(得分:0)

我正在使用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);

我希望上面的代码可以帮助您!