Spring调用存储过程

本文涉及的产品
云数据库 Redis 版,社区版 2GB
推荐场景:
搭建游戏排行榜
简介: public Boolean bindCard(final BindCardProfile bindCardProfile) throws DataAccessException { if (bindCardProfile == null) { return false; } String dbRetu
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();**
    }
相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
4月前
|
存储 XML Java
Spring中service层与存储过程的事务回滚
Spring中service层与存储过程的事务回滚
50 0
|
7月前
|
存储 Oracle Java
[亲测可用]hibernate调用Oracle存储过程|Spring Data JPA调用Oracle存储过程方法
[亲测可用]hibernate调用Oracle存储过程|Spring Data JPA调用Oracle存储过程方法
|
存储 Java 数据库
Spring Data JPA调用存储过程实例
版权声明:本文为博主chszs的原创文章,未经博主允许不得转载。 https://blog.csdn.net/chszs/article/details/50127823 Spring Data JPA调用存储过程实例 作者:chszs,未经博主允许不得转载。
1774 0
|
存储 Java 关系型数据库
使用Java Spring消费MySQL中的数据库存储过程
使用Java Spring消费MySQL中的数据库存储过程
使用Java Spring消费MySQL中的数据库存储过程
|
SQL 存储 Java
Spring(十三)之SQL存储过程
SimpleJdbcCall 类可以被用于调用一个包含 IN 和 OUT 参数的存储过程。你可以在处理任何一个 RDBMS 时使用这个方法,就像 Apache Derby, DB2, MySQL, Microsoft SQL Server, Oracle,和 Sybase。
1163 0
|
22天前
|
Java 应用服务中间件 Maven
SpringBoot 项目瘦身指南
SpringBoot 项目瘦身指南
38 0
|
2月前
|
缓存 Java Maven
Spring Boot自动配置原理
Spring Boot自动配置原理
48 0
|
30天前
|
缓存 安全 Java
Spring Boot 面试题及答案整理,最新面试题
Spring Boot 面试题及答案整理,最新面试题
106 0
|
1月前
|
前端开发 搜索推荐 Java
【Spring底层原理高级进阶】基于Spring Boot和Spring WebFlux的实时推荐系统的核心:响应式编程与 WebFlux 的颠覆性变革
【Spring底层原理高级进阶】基于Spring Boot和Spring WebFlux的实时推荐系统的核心:响应式编程与 WebFlux 的颠覆性变革
|
10天前
|
前端开发 Java 应用服务中间件
Springboot对MVC、tomcat扩展配置
Springboot对MVC、tomcat扩展配置