Пример #1
0
 public HashMap getDictSql(String sql) {
   if (sql == null) {
     Debug.getAppErrLogger().warn("字典Sql为空");
     return null;
   }
   sql = sql.trim();
   if (hashCache.containsKey(sql)) {
     //         Debug.getAppErrLogger().debug("缓存中取字典:[" + sql + "]");
     return (HashMap) hashCache.get(sql);
   } else {
     //         Debug.getAppErrLogger().debug("新缓存字典:[" + sql + "]");
     loadNewDict(sql);
     return (HashMap) hashCache.get(sql);
   }
 }
Пример #2
0
  private void loadNewDict(String sql) {
    Debug.getAppErrLogger().debug("------------------------------------------------load:" + sql);

    HashMap htemp = new HashMap();
    Statement state = null;
    ResultSet rs_dic = null;
    try {
      if (conn != null) {
        conn.close();
        conn = null;
      }
      getConnection();
      state = conn.createStatement();
      rs_dic = state.executeQuery(sql);
      while (rs_dic.next()) {
        String text = rs_dic.getString(1);
        String value = rs_dic.getString(2);
        if (null != text && value != null) {
          htemp.put(text.trim(), value.trim());
        }
      }
      hashCache.put(sql, htemp);
      rs_dic.close();
      state.close();
    } catch (Exception e) {
      e.printStackTrace();
      Debug.getAppErrLogger().error(e);
    } finally {
      try {
        if (rs_dic != null) {
          rs_dic.close();
          rs_dic = null;
        }
        if (state != null) {
          state.close();
          state = null;
        }
      } catch (Exception e) {
        Debug.getAppErrLogger().error("Inside DictCachService::loadNewDict() - 关闭时出错!\n" + e);
      }
      close();
    }
  }