Spring调用存储过程

public Boolean bindCard(final BindCardProfile bindCardProfile) throws DataAccessException {
        if (bindCardProfile == null) {
            return false;
        }

        String dbReturn = jdbcTemplate.execute(new CallableStatementCreator() {

            @Override
            public CallableStatement createCallableStatement(Connection con) throws SQLException, DataAccessException {
                // TODO Auto-generated method stub
                String stroedProc = "CALL sp_bind_card(?, ?, ?, ?, ?, ?, ?)";
                CallableStatement callableStatement = con.prepareCall(stroedProc);
                callableStatement.setString("p_cellphone", bindCardProfile.getCellphone());
                callableStatement.setString("p_name", bindCardProfile.getName());
                callableStatement.setString("p_id_card", bindCardProfile.getIdCard());
                callableStatement.setString("p_bank_card_no", bindCardProfile.getBankCardNo());
                callableStatement.setString("p_channel_name", bindCardProfile.getChannelName());
                callableStatement.setString("p_bank_abbr", bindCardProfile.getBankAbbr());
                callableStatement.registerOutParameter("p_returnVal", Types.NVARCHAR);
                return callableStatement;
            }
        }, new CallableStatementCallback<String>() {
            public String doInCallableStatement(CallableStatement callableStatement)
                    throws SQLException, DataAccessException {
                callableStatement.execute();
                return callableStatement.getString("p_returnVal");
            }
        });

        return dbReturn.equals("success");
    }

1 在类中使用Spring管理对象时,同时又用Spring对象实例话另一个对象时,注意其位置,如下面的代码,这样定义时会Error,会出现空的指针,具体可能在初始化对象时,和Spring的先后顺序有关

//@Repository
public class CacheKeyManager {

    @Resource(name="stringRedisTemplate")
    private RedisTemplate<String, String> redisTemplate;
    **RedisSerializer<String> stringSerializer=redisTemplate.getStringSerializer();**
    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值