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

  • 相关阅读:
    mysql 函数
    flanneld和calico
    k8s1.20.5
    pre
    docker与K8S源远
    Form Trigger Sequence Demo Form
    消息中间件RabbitMQ
    asp.net mvc4压缩混淆JavaScript
    C# 基础语法
    APP测试 理论总结
  • 原文地址:https://www.cnblogs.com/nizuimeiabc1/p/4254147.html
Copyright © 2011-2022 走看看