public void run() { try { PreparedStatement pstmt = con.prepareStatement( "insert into #testConcurrentBatch (v1, v2, v3, v4, v5, v6) values (?, ?, ?, ?, ?, ?)"); for (int i = 0; i < 64; ++i) { // Make sure we end up with 64 different prepares, use the binary representation of i to // set each // of the 6 parameters to either an int or a string. int mask = i; for (int j = 1; j <= 6; ++j, mask >>= 1) { if ((mask & 1) != 0) { pstmt.setInt(j, i); } else { pstmt.setString(j, String.valueOf(i)); } } pstmt.addBatch(); } int x[]; try { x = pstmt.executeBatch(); } catch (BatchUpdateException e) { e.printStackTrace(); x = e.getUpdateCounts(); } if (x.length != 64) { throw new SQLException("Expected 64 update counts, got " + x.length); } for (int i = 0; i < x.length; ++i) { if (x[i] != 1) { throw new SQLException("Error at position " + i + ", got " + x[i] + " instead of 1"); } } // Rollback the transaction, exposing any race conditions. con.rollback(); pstmt.close(); } catch (SQLException ex) { ex.printStackTrace(); exceptions.add(ex); } }