zoukankan      html  css  js  c++  java
  • spring jdbc 源码

    类:org.springframework.jdbc.core.JdbcTemplate

    public <T> T execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action)
                throws DataAccessException {
    
            Assert.notNull(psc, "PreparedStatementCreator must not be null");
            Assert.notNull(action, "Callback object must not be null");
            if (logger.isDebugEnabled()) {
                String sql = getSql(psc);
                logger.debug("Executing prepared SQL statement" + (sql != null ? " [" + sql + "]" : ""));
            }
         //获取数据连接
            Connection con = DataSourceUtils.getConnection(getDataSource());
            PreparedStatement ps = null;
            try {
                Connection conToUse = con;
                if (this.nativeJdbcExtractor != null &&
                        this.nativeJdbcExtractor.isNativeConnectionNecessaryForNativePreparedStatements()) {
                    conToUse = this.nativeJdbcExtractor.getNativeConnection(con);
                }
                ps = psc.createPreparedStatement(conToUse);
                applyStatementSettings(ps);
                PreparedStatement psToUse = ps;
                if (this.nativeJdbcExtractor != null) {
                    psToUse = this.nativeJdbcExtractor.getNativePreparedStatement(ps);
                }
                T result = action.doInPreparedStatement(psToUse);
                handleWarnings(ps);
                return result;
            }
            catch (SQLException ex) {
                // Release Connection early, to avoid potential connection pool deadlock
                // in the case when the exception translator hasn't been initialized yet.
                if (psc instanceof ParameterDisposer) {
                    ((ParameterDisposer) psc).cleanupParameters();
                }
                String sql = getSql(psc);
                psc = null;
                JdbcUtils.closeStatement(ps);
                ps = null;
                DataSourceUtils.releaseConnection(con, getDataSource());
                con = null;
                throw getExceptionTranslator().translate("PreparedStatementCallback", sql, ex);
            }
            finally {
                if (psc instanceof ParameterDisposer) {
                    ((ParameterDisposer) psc).cleanupParameters();
                }
                JdbcUtils.closeStatement(ps);
                DataSourceUtils.releaseConnection(con, getDataSource());
            }
        }
  • 相关阅读:
    Document
    Document
    Document
    css3 无缝轮播效果小demo(轮播效果/渐隐渐现效果)
    4.Redux (这篇文章需要修改)
    3.React-router/BrowserRouter/withRouter/Switch/history/exact/strict/Link/Redirect/PropTypes
    2.React数据传递 之☞ 父子之间数据传递 / React生命周期
    1.React (基础篇)
    13. Vuex ,一个专为 Vue.js 应用程序开发的状态管理模式
    12. vue 路由(vue-router)
  • 原文地址:https://www.cnblogs.com/fuyuanming/p/5857200.html
Copyright © 2011-2022 走看看