title: Why Spring's jdbcTemplate.batchUpdate() so slow?
body: <p>I'm trying to find the faster way to do batch <strong>insert</strong>.</p>
  
  <p>I tried to insert several batches with <strong>jdbcTemplate.update(String sql)</strong>, where 
  sql was builded by StringBuilder and looks like:</p>
  
  <pre><code>INSERT INTO TABLE(x, y, i) VALUES(1,2,3), (1,2,3), ... , (1,2,3)
  </code></pre>
  
  <p>Batch size was exactly 1000. I inserted nearly 100 batches.
  I checked the time using StopWatch and found out insert time:</p>
  
  <pre><code>min[38ms], avg[50ms], max[190ms] per batch
  </code></pre>
  
  <p>I was glad but I wanted to make my code better.</p>
  
  <p>After that, I tried to use jdbcTemplate.batchUpdate in way like: </p>
  
  <pre><code>    jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
          @Override
          public void setValues(PreparedStatement ps, int i) throws SQLException {
                         // ...
          }
          @Override
          public int getBatchSize() {
              return 1000;
          }
      });
  </code></pre>
  
  <p>where sql was look like </p>
  
  <pre><code>INSERT INTO TABLE(x, y, i) VALUES(1,2,3);
  </code></pre>
  
  <p>and I was disappointed! jdbcTemplate executed every single insert of 1000 lines batch in separated way. I loked at mysql_log and found there a thousand inserts.
  I checked the time using StopWatch and found out insert time:</p>
  
  <p>min[900ms], avg[1100ms], max[2000ms] per Batch</p>
  
  <p>So, can anybody explain to me, why jdbcTemplate doing separated inserts in this method? Why method's name is <strong>batchUpdate</strong>? 
  Or may be I am using this method in wrong way?</p>