title: Singleton in JSP, how to properly tidy up on close?
body: <p>I am just getting started with jsp and my question is this - when I have a singleton class, how do I tidy up after it?</p>
  
  <p>In particular:</p>
  
  <pre><code>public class DBConnection {
    private static Connection connection = null;
    private static Statement statement = null;
  
    public static ResultSet executeQuery(String query){
      if (connection == null) { /*initConnection*/ }
      if (statement == null) { /*initStatement*/ }
  
      // do some stuff
    }
  }
  </code></pre>
  
  <p>Now, I use this class in several pages to get results from jdbc. However, I need to eventually call <code>statement.close();</code> and <code>connection.close();</code> - when should I call those? </p>
  
  <p>I am using singleton, because it felt wrong to call for connection to a database over and over whenever I needed to make a query.</p>