How to call Oracle function or stored procedure using spring persistence framework?

后端 未结 4 1499
忘掉有多难
忘掉有多难 2020-12-13 15:57

I am using Spring persistence framework for my project. I want to call oracle function or stored procedure from this framework.

Can anybody suggest how can I achieve

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 16:37

    In my opinion this is one of the easiest approaches:

    public class ServRepository {
    
        private JdbcTemplate jdbcTemplate;
        private SimpleJdbcCall functionGetServerErrors;
    
        @Autowired
        public void setDataSource(DataSource dataSource) {
            this.jdbcTemplate = new JdbcTemplate(dataSource);
            JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
            jdbcTemplate.setResultsMapCaseInsensitive(true);
            this.functionGetServerErrors = new SimpleJdbcCall(jdbcTemplate).withFunctionName("THIS_IS_YOUR_DB_FUNCTION_NAME").withSchemaName("OPTIONAL_SCHEMA_NAME");
        }
    
            public String callYourFunction(int parameterOne, int parameterTwo) {
                SqlParameterSource in = new MapSqlParameterSource().addValue("DB_FUNCTION_INCOMING_PARAMETER_ONE", parameterOne).addValue("DB_FUNCTION_INCOMING_PARAMETER_TWO", parameterTwo);
                return functionGetServerErrors.executeFunction(String.class, in);
            }
    }
    

提交回复
热议问题