title: PostgreSQL 9.3 executeBatch command
body: <p>I am adding the following commands to batch and execute it by invoking <code>executeBatch()</code> JDBC function.</p>
  
  <pre><code>insert into blabla (id,value) values ('1','666666')
  insert into blabla (id,value) values ('1','8888')
  </code></pre>
  
  <p><code>id</code> is unique.</p>
  
  <p>I expect that the first sql command will work and be committed to DB.  </p>
  
  <p>The API of the <code>executeBatch()</code> command indicates that when <code>BatchUpdateException</code> exception is thrown, all the previous SQL that succeed will be committed to the DB. </p>
  
  <p>Actual result is that no sql command is committed to the DB. Why?</p>
  
  <p>I'm using the following syntax: </p>
  
  <pre><code>int[] res = null;
  try {
       conn.setAutoCommit(false);
       Statement batch_stmt = conn.createStatement();
       for (String sql: sqlList) {
            batch_stmt.addBatch(sql);
       }
       res = batch_stmt.executeBatch();
  
       conn.commit();
       batch_stmt.clearBatch();
       batch_stmt.close();
  } catch (BatchUpdateException e) {
           int[] err_res = e.getUpdateCounts();   
           try {
             conn.commit();
           } catch (SQLException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
           }
  } catch (SQLException e) {
           e.printStackTrace();
  }
  </code></pre>
  
  <p>Also I tried auto commit true and I got the same results. </p>
  
  <pre><code>int[] res = null;
  
  try {
       Statement batch_stmt = conn.createStatement();
       for (String sql: sqlList) {
            batch_stmt.addBatch(sql);
       }
  
       res = batch_stmt.executeBatch();
       batch_stmt.clearBatch();
       batch_stmt.close();
  } catch (BatchUpdateException e) {
           int[] err_res = e.getUpdateCounts();   
  } catch (SQLException e) {
           e.printStackTrace();
  }
  </code></pre>
  
  <p>By the way, <code>e.getUpdateCounts();</code> returned that first sql did succeed.</p>