title: Why JDBC connections needs to close in finally block?
body: <pre><code>Connection conn = null;
  Statement stmt = null; 
  ResultSet rs = null;
  try
  {
      conn = geting the connection object ( using DriverManager.getConnection() method or using connection pool)
      stmt = conn.createStatement ("select ...");
     // some other logic here
  }
  catch (SQLException e)
  {
      // handling the exceptions
  }
  finally
  {
  
  }
  </code></pre>
  
  <p>Here my question is while closing the connection object in the following cases what are the problems it will come.</p>
  
  <ol>
  <li><p>Assume if there is no exception occurred, in <strong>try block</strong> there it self closing the connection object.</p>
  
  <pre><code>try {
       // same above code 
       stmt.close();
       conn.close();
  } catch(Exception ex) {
      // handling the exceptions
  } finally {
  
  }
  </code></pre></li>
  <li><p>If some exception is occured so it will goes to <strong>catch block</strong>, there it self closing the connection object.</p>
  
  <pre><code>try {
       // same above code 
  
  } catch(Exception ex) {
      // handling the exceptions
      stmt.close();
      conn.close();
  } finally {
  
  }
  </code></pre></li>
  <li><p>Closing the connection object in <strong>finally block</strong>.</p>
  
  <pre><code>try {
       // same above code 
  
  } catch(Exception ex) {
      // handling the exceptions
  
  } finally {
      stmt.close();
      conn.close();
  } 
  </code></pre></li>
  <li>Difference between closing the connection object using close() method and closing the pooled connection using close().</li>
  </ol>
  
  <p><strong>Note:</strong> Please don't say closing the connection object in finally block is good. I know that one. If i keep the close connection in try block, catch block is there any problems please explain.</p>