spring JdbcTempalte 执行存储过程

1. 执行无返回值的存储过程

[java]  view plain copy
  1. (1)  
  2. public void deleteCheckedRecors(String rootInstId,String tableName,String primarykey,String bizguidValue)throws Exception{  
  3.         try{  
  4.             String procedure = "{call sp_deleteInstByRootID('"+rootInstId+"')}";  
  5.             this.getJdbcTemplate().execute(procedure);      }catch(Exception e){  
  6.             e.printStackTrace();  
  7.         }  
  8. }  
  9.   
  10. (2)  
  11. public int addORDelAgentPerson(final String strTableID,final String strUserID,final String strAgentID,final String strType)throws Exception{  
  12.         String procedure = "{call SP_SetDevolvePerson(?,?,?,?)}";  
  13.         try{  
  14.             this.getJdbcTemplate().execute(procedure, new CallableStatementCallback(){  
  15.                 public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {  
  16.                     cs.setString(1, strTableID);  
  17.                     cs.setString(2, strUserID);  
  18.                     cs.setString(3, strAgentID);  
  19.                     cs.setString(4, strType);  
  20.                     cs.execute();  
  21.                     return cs;  
  22.                 }  
  23.             });  
  24.             return 1;  
  25.         }catch(Exception e){  
  26.             e.printStackTrace();  
  27.             return 0;  
  28.         }  
  29.     }  

2.执行有返回值的存储过程

[java]  view plain copy
  1. public Map testProcdure(final String uerId)throws Exception{  
  2.         String procedure = "{call SP_GetUserInfo(?,?,?,?)}";  
  3.          Map map = null;  
  4.         try{  
  5.             map = (Map) this.getJdbcTemplate().execute(procedure, new CallableStatementCallback(){  
  6.                 public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {  
  7.                     cs.setString(1,uerId);//输入参数  
  8.                     cs.registerOutParameter(2,OracleTypes.VARCHAR); //输出参数  
  9.                     cs.registerOutParameter(3,OracleTypes.VARCHAR);//输出参数  
  10.                     cs.registerOutParameter(4,OracleTypes.VARCHAR);//输出参数  
  11.                     cs.execute();  
  12.                     Map newMap = new HashMap();   
  13.                     newMap.put("name", cs.getString(2));  
  14.                     newMap.put("telephone",cs.getString(3));  
  15.                     newMap.put("post",cs.getString(4));  
  16.                     return newMap ;  
  17.                 }  
  18.             });  
  19.         }catch(Exception e){  
  20.             e.printStackTrace();  
  21.         }  
  22.         return map;  
  23.     }  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值