Ejemplo n.º 1
0
 /**
  * 获得数据库连接
  *
  * @return : 一个连接
  */
 public void getConnection() {
   if (conn == null) {
     try {
       conn = dbManager.getConnection();
     } catch (SQLException ex) {
       Debug.getAppErrLogger().error("取数据库连接错误!", ex);
     }
   }
 }
Ejemplo n.º 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();
    }
  }
Ejemplo n.º 3
0
 /** 释放数据库连接 */
 public void close() {
   if (conn != null) {
     try {
       dbManager.freeConnection(conn);
       conn = null;
     } catch (SQLException ex) {
       Debug.getAppErrLogger().error("释放数据库连接错误!", ex);
     }
   }
 }
Ejemplo n.º 4
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);
   }
 }
Ejemplo n.º 5
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;
 }