title: Should I keep opening and closing connections in JSP
body: <p>I created a Class called MySQL.</p>
  
  <p>This Class contains only 1 method, which connects me to my database.</p>
  
  <pre><code>public static void Connect() {
      try {
          Class.forName("com.mysql.jdbc.Driver");
      } catch (ClassNotFoundException ex) {
          System.out.println(ex.getMessage());
      }
      try {
  
          connection = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/"+database,username,password);
  
      } catch (SQLException ex) {
          System.out.println(ex.getMessage());
      }
  }
  </code></pre>
  
  <p>So now, when I need to connect inside a JSP page, I write this.</p>
  
  <pre><code>&lt;% MySQL.Connect();
     Statement stmt = MySQL.getConnection().createStatement();
     ResultSet rset = stmt.executeQuery("....");
     //Some codes here
     //Then I close both rset and stmt
     rset.close();
     stmt.close();
  %&gt;
  </code></pre>
  
  <p>Should I close the connection as well? note that there will be more queries executed when the page is loaded, should I work on 1 connection for all queries or 1 connection for each query and then close it?</p>