JdbcTemplate调用Oracle存储过程

JdbcTemplate调用Oracle存储过程封装类

利用STRUCT和ARRAY实现给Oracle传入数组合Oracle自定义类型。

OracleUtil 抽象类定义参数封装、返回结果封装方法和存储过程调用的实现。


package com.ytkj.adisp.pax.common;

import com.google.common.collect.Lists;
import com.ytkj.adisp.common.ano.OracleDataType;
import com.ytkj.adisp.common.dto.CommonResultDTO;
import com.ytkj.adisp.common.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import oracle.jdbc.OracleConnection;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import oracle.sql.STRUCT;
import oracle.sql.StructDescriptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.CallableStatementCallback;
import org.springframework.jdbc.core.CallableStatementCreator;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;

import java.lang.reflect.Field;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

[@Slf4j](https://my.oschina.net/slf4j)
[@Service](https://my.oschina.net/service)
public abstract class OracleUtil {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public CommonResultDTO dealProc(String procedureName, Map<String, Object> in, Map<String, Integer> out) {

        CommonResultDTO commonResult = jdbcTemplate.execute(
                new CallableStatementCreator() {
                    [@Override](https://my.oschina.net/u/1162528)
                    public CallableStatement createCallableStatement(Connection connection) throws SQLException {
                        if (connection.isWrapperFor(OracleConnection.class)) {
                            connection = connection.unwrap(OracleConnection.class);
                        }
                        return deal(connection, procedureName, in, out);
                    }
                },
                new CallableStatementCallback<CommonResultDTO>() {
                    [@Nullable](https://my.oschina.net/u/2896689)
                    @Override
                    public CommonResultDTO doInCallableStatement(Callab
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值