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容器管理,性能提升不少。

  • 相关阅读:
    1月19号 UIImageView
    1月18号 UILabel 加上导入.tff格式的字体
    1月18号 UIButton
    2016年 1月15号 cocoapods的导入
    1月12号 UIView
    12月30号 iOS程序准备
    12月29号 计算器(包含混合运算)
    2016.01.13 代理设计模式
    2016.01.04 视图控制器UIViewController
    2015.12.31 iOS程序准备(developer.apple.com)
  • 原文地址:https://www.cnblogs.com/nizuimeiabc1/p/4254147.html
Copyright © 2011-2022 走看看