コード例 #1
0
 /**
  * The main program for the DictCachService class
  *
  * @param args The command line arguments
  */
 public static void main(String[] args) {
   HashMap h = DictCachService.getInstance().getDictSql("select * from tab");
   HashMap h2 = DictCachService.getInstance().getDictSql("select * from tab");
   HashMap hash = DictCachService.getInstance().getDictSql("select code ,name from t_kouan");
   Iterator itor1 = hash.keySet().iterator();
   while (itor1.hasNext()) {
     String code = (String) itor1.next();
     String text = (String) hash.get(code);
     System.out.println(code + "  " + text);
   }
 }
コード例 #2
0
 public String getTextOfDic(String strSql) {
   String returnValue = "";
   Debug.getAppErrLogger().debug("get select text's sql is:" + strSql);
   if (strSql != null && !strSql.equals("")) {
     HashMap hp = getDictSql(strSql);
     Iterator it = hp.keySet().iterator();
     String sText = "";
     while (it.hasNext()) {
       sText = (String) it.next() + ",";
     }
     if (sText.length() > 0 && sText.lastIndexOf(",") == (sText.length() - 1)) {
       sText = sText.substring(0, sText.lastIndexOf(","));
     }
     returnValue = sText;
   }
   return returnValue;
 }
コード例 #3
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();
    }
  }