title: Memory leaks in Java: database connection in multiple methods
body: <p>I've build a crawler which is currently experiencing Memory leaks at a speed of 600MB/day. I think the cause is database connection.
  Currently, I'm creating a single database connection as a static method as follows:</p>
  
  <pre><code>static
  {       
      try
      {
          String hostname = PropertyReader.getProperty("hostname");
          String port = PropertyReader.getProperty("port");
          String dbname = PropertyReader.getProperty("dbname");
          String username = PropertyReader.getProperty("username");
          String password = PropertyReader.getProperty("password");
  
          Class.forName("com.mysql.jdbc.Driver");
          String url = "jdbc:mysql://"+hostname+":"+port+"/"+dbname+"";
          conn = DriverManager.getConnection(url, username, password);
          System.out.println("conn built");
      }
      catch (SQLException e)
      {
          e.printStackTrace();
      } catch (ClassNotFoundException e)
      {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>and I'm using this variable in multiple methods as follows:</p>
  
  <pre><code>public static void getSeed()
  
  public static void processPage(String URL)
  </code></pre>
  
  <p>for retrieving and inserting data into database.</p>
  
  <p>What is the best alternate to avoid memory leaks ?</p>