title: Arval SQLException: FATAL: sorry, too many clients already in postgres
body: <p>I am using a database in PostgreSQL 9.1,in which entry are coming continuously from another program . I am sending request from Ajax after 6 sec to fetch the latest entry.tomcat output window shows exception--- </p>
  
  <pre><code>Arval SQLException: FATAL: sorry, too many clients already
  </code></pre>
  
  <p>and program is working correctly also after this.
    When i check my postgres with query--- </p>
  
  <pre><code>select count(*) from pg_stat_activity;
  </code></pre>
  
  <p>it shows that connection are increasing continuously but I close the connection after each request.I am using netbeans and struts 1.3.       </p>
  
  <pre><code>     long previousSNO = Long.parseLong(request.getParameter("previousSNO"));
      if(previousSNO == 0)
      {
          sb.append("SELECT sno,search_type,search_value,search_date FROM log_temp ORDER BY search_date DESC LIMIT 20");
          prest = cb.executeSQLQuery(sb.toString());
          rs = prest.executeQuery();
      }
      else
      {
          sb.append("SELECT sno,search_type,search_value,search_date FROM log_temp WHERE sno &gt; ? ORDER BY search_date DESC");
          prest = cb.executeSQLQuery(sb.toString());    
          prest.setLong(1, previousSNO);
          rs = prest.executeQuery();
      }
      rs.last();
      int c = rs.getRow();
      rs.beforeFirst();
  
      if(rs!=null &amp;&amp; c&gt;0)
      {    
      //code for making json resultsb from resultset here    
      rs.close();
      }
      cb.closeConnection();
      response.setContentType("text/plain");
      response.getWriter().print(resultsb.toString());
  </code></pre>
  
  <p>//and close method in connection bean is</p>
  
  <pre><code>    public void closeConnection() {
      try {
          // st.close();
          conn.close();
          System.out.println("con is closed");
          conn = null;
  
      } catch (SQLException e) {
          e.getMessage();
          System.out.println(e.getMessage());
          System.out.println("con is not closed");
      }
  }
  </code></pre>
  
  <p>Every time its print on console " con is closed";</p>