zoukankan      html  css  js  c++  java
  • Spring jdbc call oralce procedure or function

    1. spring jdbc call oralce procedure:
    final String callFunctionSql = "{call SP_Test(?,?,?)}";  
            
            List<SqlParameter> params = new ArrayList<SqlParameter>();  
            params.add(new SqlParameter(Types.INTEGER));  
            params.add(new SqlReturnResultSet("result",  
                    new ResultSetExtractor<Integer>() {  
                @Override  
                public Integer extractData(ResultSet rs) throws SQLException,DataAccessException {  
                    while(rs.next()) {  
                        return rs.getInt(1);  
                    }  
                   return 0;  
            }})); 
            
            Map<String,Object> map =  getJdbcTemplate().call(new CallableStatementCreator()
            {
    
                @Override
                public CallableStatement createCallableStatement(Connection conn) throws SQLException
                {
                    CallableStatement cstmt = conn.prepareCall(callFunctionSql);  
                    cstmt.setInt(1, 2);
                    cstmt.setInt(2, 16);
                    cstmt.setInt(3, 10);
                    return cstmt;  
                }
                
            }, params);
            
    

    2.Spring jdbc call oracle function

    String i = getJdbcTemplate().execute("{?=call FN_UPDATE_BUSINESS_UNIT(?,?,?)}", new CallableStatementCallback<String>() {
                    public String doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
                        cs.registerOutParameter(1, java.sql.Types.VARCHAR);
                        cs.setInt(2, 2);
                        cs.setInt(3, 16);
                        cs.setInt(4, 8);
                        cs.execute();
                        return cs.getString(1);
                    }
                });



  • 相关阅读:
    设计模式之观察者模式
    设计模式之备忘录模式
    设计模式之中介者模式
    设计模式之迭代器模式
    设计模式之解释器模式
    设计模式之命令模式
    设计模式之职责链模式
    设计模式之代理模式
    设计模式之享元模式
    设计模式之外观模式
  • 原文地址:https://www.cnblogs.com/xue88ming/p/7183010.html
Copyright © 2011-2022 走看看