zoukankan      html  css  js  c++  java
  • JdbcTemplate中的exectue和queryForList方法的性能对比

    @Autowired
    JdbcTemplate jdbcParam;

    pstm =
                    jdbcParam.getDataSource()
                        .getConnection()
                        .prepareStatement(" SELECT T.ID, T.EPARCHY_CODE FROM  TD_B_SPECIALID_HOME T WHERE T.ID_TYPE = 2 ");
                result = pstm.executeQuery();
                long acctId;
                String eparchyCode;
                while (result.next())
                {
                    acctId = result.getLong("ID");
                    eparchyCode = result.getString("EPARCHY_CODE");
                    specialAcctIdWithEparchyCodeMap.put(acctId, eparchyCode);
                }
            }
            catch (Exception e)
            {
                logger.error("run initSpecialAcctIdWithEparchyCodeMap error.", e);
            }
            finally
            {
                try
                {
                    if (!result.isClosed())
                    {
                        result.close();
                    }
                }
                catch (SQLException e)
                {
                    logger.error("Can not close resultset conn.", e);
                }
                finally
                {
                    try
                    {
                        if (!pstm.isClosed())
                        {
                            pstm.close();
                        }
                    }
                    catch (SQLException e)
                    {
                        logger.error("Can not close preparedstatment conn.", e);
                    }
                }
            }

    以上代码:需要打开preparedStatement和ResultSet连接,影响性能

    而用jdbcParam.queryForList(sql,new Object[]{},Integer.class);

    不需要做打开连接关闭连接动作,直接由spring容器管理,性能提升不少。

  • 相关阅读:
    寒假学习第九天
    寒假学习第八天
    寒假学习第七天
    寒假学习第六天
    input框输入金额限制
    jsp页面截取字符串,显示指定长度
    循环随机变更数据库表中某个字段的值为指定的值
    jQuery MD5加密实现代码
    jquery $(document).ready() 与window.onload的区别
    node,不懂不懂
  • 原文地址:https://www.cnblogs.com/nizuimeiabc1/p/4254147.html
Copyright © 2011-2022 走看看