title: Connection.close() does not closes the connection, it make it sleep forever?
body: <p>In my web app which I write it with java and it uses tomcat and sql server, I can not close the database connections by typing connection.close(). When I write sp_who to the SSMS I can see that sleeping connections count which is opened by me increases while my app is doing sql stuffs.</p>
  
  <p>An example code is in below:</p>
  
  <pre><code>BaseRepository baseRepository = new BaseRepository();
  try{
      baseRepository.createStatement();
  
      baseRepository.stmt.executeUpdate("update AutoRunURLs set STATUS = 0");
  
  }catch (SQLException e){
      e.printStackTrace();
  }finally {
      baseRepository.cleanResources();
  }
  </code></pre>
  
  <p>Here is the other functions that I used above:</p>
  
  <pre><code>public void openConnection() {
      try {
          this.conn = ds.getConnection(); // ds is an instance of javax.sql.DataSource
          this.isOpen = true;
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  
   public void createStatement() {
      try {
          if (!this.isOpen) this.openConnection();
          this.stmt = this.conn.createStatement();
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  
  public void cleanResources() {
      try {
          if (this.rs != null) {
              rs.close();
              this.rs = null;
          }
          if (this.stmt != null) {
              stmt.close();
              this.stmt = null;
          }
          if (this.conn != null) {
              this.closeConnection();
          }
      } catch (Exception e) {
          e.printStackTrace();
      } finally {
          if (this.conn != null) this.closeConnection();
      }
  }
  
   public void closeConnection() {
      try {
          if (this.conn != null){
              this.conn.close();
          }
          this.isOpen = false;
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>When I run the first part above which starts with <code>BaseRepository baseRepository ...</code> one sleeping connections occurs which I see with typing sp_who and it does not close(I waited about a day). Why is that? How can I prevent from this?</p>
  
  <p>And I got one more situation. In my tomcat configurations I set the "maxIdle" value to 10 but even that sleeping connections increases up to thousands after a week. Why does maxIdle does not effect? Here is how I set it:</p>
  
  <pre><code>&lt;Context&gt;
  
  &lt;!-- Default set of monitored resources. If one of these changes, the    --&gt;
  &lt;!-- web application will be reloaded.                                   --&gt;
  &lt;WatchedResource&gt;WEB-INF/web.xml&lt;/WatchedResource&gt;
  &lt;WatchedResource&gt;${catalina.base}/conf/web.xml&lt;/WatchedResource&gt;
  &lt;Resource auth="Container" driverClassName="net.sourceforge.jtds.jdbc.Driver" maxTotal="999999" maxIdle="10" "Database info here..." validationQuery="select 1"/&gt;
  &lt;!-- Uncomment this to disable session persistence across Tomcat restarts --&gt;
  &lt;!--
  &lt;Manager pathname="" /&gt;
  --&gt;
  </code></pre>
  
  <p></p>
  
  <p>How can I solve these? Regards,</p>
  
  <hr>
  
  <p>Edit: I actually managed it by creating a scheduled task which runs every x minutes and kills sleeping connections that sleeps over y minutes. But this is not the way I want. Any other solution will be great.</p>