title: Closing database connections in Java
body: <p>I am getting a little confused. I was reading the below from <em><a href="http://en.wikipedia.org/wiki/Java_Database_Connectivity" rel="noreferrer">Java Database Connectivity</a></em>:</p>
  <pre><code>Connection conn = DriverManager.getConnection(
       &quot;jdbc:somejdbcvendor:other data needed by some jdbc vendor&quot;,
       &quot;myLogin&quot;,
       &quot;myPassword&quot; );
  
  Statement stmt = conn.createStatement();
  try {
      stmt.executeUpdate( &quot;INSERT INTO MyTable( name ) VALUES ( 'my name' ) &quot; );
  } finally {
      // It's important to close the statement when you are done with it
      stmt.close();
  }
  </code></pre>
  <p>Do you not need to close the <code>conn</code> connection?
  What is really happening if the conn.close() doesn't occur?</p>
  <p>I have a private web application I'm maintaining that doesn't currently close either form, but is the important one really the <code>stmt</code> one, the <code>conn</code> one, or both?</p>
  <p>The site keeps going down intermittently, but the server keeps saying it's a database connection issue. My suspicion is that it's not being closed, but I don't know which, if any, to close.</p>