title: Right way to use JDBC Statement batching
body: <p>Trying to use sql statement batchs to do the following: every 5 minutes, add a statement to batch (current counter) then every hour send, send the statements to the database.</p>
  
  <p>I'm curious though, do I need to reinitialize the statement/connection whenever I add to it or send the batch?</p>
  
  <p>here's how i think i would go about doing this, just need some clarification on how to do it smarter or if this is the best way</p>
  
  <p>on program startup, initialize the following</p>
  
  <pre><code>    Connection connection = null;
      Statement statement = null;
          Class.forName("com.mysql.jdbc.Driver");
          connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/youtube", "root", "root");
      statement = connection.createStatement();
  </code></pre>
  
  <p>then every 5 minutes....
  addToBatch(connection, statement, counter, time, date);</p>
  
  <p>then hour...
  statement.executeBatch();</p>
  
  <p>am i missing anything? do i need to remake the connection?</p>
  
  <p>any information is helpful, thank you!</p>