首页 > 代码库 > spring heibernate 调用存储过程

spring heibernate 调用存储过程

一:参考网址

http://sunbin123.iteye.com/blog/1007556

二:示例

   @Autowired
    @Qualifier("jdbcTemplate")
    private JdbcTemplate jdbcTemplate;
  @SuppressWarnings("unchecked")
    public Integer GetSerNo() {   
          Integer param2Value =  jdbcTemplate.execute(   
             new CallableStatementCreator() {   
                public CallableStatement createCallableStatement(Connection con) throws SQLException {   
                   String storedProc = "{call getSNo(?,?)}";// 调用的sql   
                   CallableStatement cs = con.prepareCall(storedProc);   
                   cs.setString(1, sno);// 设置输入参数的值   
                   cs.registerOutParameter(2, java.sql.Types.INTEGER);
                   return cs;   
                }   
             }, new CallableStatementCallback() {   
                 public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {   
                   cs.execute();   
                   return cs.getInt(2);// 获取输出参数的值   
             }   
          }); 
          return param2Value;
        }  
    

 

spring heibernate 调用存储过程