zoukankan      html  css  js  c++  java
  • spring调用存储过程

    1.继承StoredProcedure

    org.springframework.jdbc.object.StoredProcedure是对应存储过程调用的操作对象,它通过其父类

    org.springframework.jdbc.object.SqlCall获得相应的底层API支持(CallableStatementCreator), 然

    后在此基础之上构建了调用存储过程的执行方法。

    2、重写父类的execute()方法。将存储过程的参数封装成Map类型的传入该方法

    .
    3、写一个方法来封装存储过程的方法及把参数放到Map里面.

    如:
      Map paraMap = new HashMap();
      paraMap.put(IN_PARAMETER_NAME, tableName);
      paraMap.put(INOUT_PARAMETER_NAME, v);
    注意:key值一定要与前面构造函数里面声明的参数一致。


    4、execute()返回的map值要取到里面的value值,可以用前面构造函数声明时候用到的key值去取。
      如:(String)resultMap.get(OUT_PARAMETER_NAME);就得到了存储过程的返回值。

    示例如下:

    public class xxxxProcedure extends StoredProcedure {
        private static final String PROCEDURE_NAME = "xxxx";

        protected xxxxProcedure() {
            /* empty */
            }
        
        public xxxxProcedure(JdbcTemplate jdbcTemplate) {
            super(jdbcTemplate, PRO_NAME);
            declareParameter(new SqlParameter("xxxx", Types.VARCHAR));
            declareParameter(new SqlParameter("xxxx", Types.VARCHAR));
            declareParameter(new SqlParameter("xxxx", Types.NUMERIC));
        }

        public void execute(String xxxx,String xxxx,int xxxx) {
            Map<String, Object> paramsIn = new HashMap<String, Object>();
            paramsIn.put("xxxx", xxxx);
            paramsIn.put("xxxx", xxxx);
            paramsIn.put("xxxx", xxxx);
            super.execute(paramsIn);
        }

    }

  • 相关阅读:
    Java代码输出到txt文件(申请专利贴源码的必备利器)
    Vmware10组建局域网
    Ubuntu14.04更换阿里云源
    Ubuntu16.04如何彻底删除Apache2
    HustOJ平台搭建
    Centos 7 联想Y430P无线网卡驱动安装 过程参考
    Windows远程CentOS桌面
    centos 7 查看系统/硬件信息及运维常用命令+联想Y430P无线网卡驱动安装
    zookeeper工作原理、安装配置、工具命令简介
    centos 7 安装五笔输入法
  • 原文地址:https://www.cnblogs.com/davidwang456/p/2873763.html
Copyright © 2011-2022 走看看