开发者社区> kuoren> 正文

Spring调用存储过程

简介: 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();**
    }

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
使用Java Spring消费MySQL中的数据库存储过程
使用Java Spring消费MySQL中的数据库存储过程
64 0
Spring(十三)之SQL存储过程
SimpleJdbcCall 类可以被用于调用一个包含 IN 和 OUT 参数的存储过程。你可以在处理任何一个 RDBMS 时使用这个方法,就像 Apache Derby, DB2, MySQL, Microsoft SQL Server, Oracle,和 Sybase。
1093 0
Spring Data JPA调用存储过程实例
版权声明:本文为博主chszs的原创文章,未经博主允许不得转载。 https://blog.csdn.net/chszs/article/details/50127823 Spring Data JPA调用存储过程实例 作者:chszs,未经博主允许不得转载。
1547 0
《Spring Boot 2.5开发实战》电子版地址
本书全面覆盖了 Spring Boot 2.5 新特性、自动化配置原理、如何开发 REST API、 实战 MySQL 数据库、Redis 高并发缓存、MongoDB 数据库、MQ 消息队列、安全机制、 性能监控、高级面试题等热门知识点。
95 0
「Spring」Boot Docker 认证指南(下)
「Spring」Boot Docker 认证指南(下)
165 0
「Spring」Boot Docker 认证指南(上)
「Spring」Boot Docker 认证指南(上)
77 0
Spring Boot demo系列 :Redis缓存
目录 Spring Boot demo系列 :Redis缓存 12.2.1 手动添加`@class` 12.2.2 将实体类设置为`open`
287 0
Spring Boot 操作 Redis 的各种实现
Spring Boot 操作 Redis 的各种实现
217 0
Spring Boot 的 HTTP 客户端框架
Spring Boot 的 HTTP 客户端框架
509 0
Spring Boot 项目 启动 端口经常被占用 彻底解决方案
Spring Boot 项目 启动 端口经常被占用 彻底解决方案
537 0
+关注
kuoren
五年互联网金融开发经验;知名互联网P2P平台核心交易自动化开发;常用开发语言Java、C#、Python;熟练Linux命令使用
文章
问答
文章排行榜
最热
最新
相关电子书
更多
电商网站需求分析和架构设计Spring Boot2.6入门
立即下载
云上Docker的Spring Cloud微服务应用实践分享
立即下载
Spring Boot 2.6.0电商网站开发实战
立即下载
相关实验场景
更多