title: Can I SELECT with LAST_INSERT_ID() after INSERT Batch without any cares?
body: <p>I'm asking myself if it is possible to <code>SELECT</code> with <code>LAST_INSERT_ID()</code> in <code>WHERE</code> Clause after an batch of <code>INSERT</code>s without getting corrupt data in the tables? I'm thinking of the scenario that multiple users doing the same stuff at the same time. I develop an JSF Application in which this scenario can be possible.</p>
  
  <p>In hard Code my <code>SELECT</code> after <code>INSERT</code>s looks like this:</p>
  
  <pre><code>preparedstatement.addBatch(
                "INSERT INTO table1(all the FIELDS)"
                + "VALUES(null, ...);"
        );
  
        preparedstatement.addBatch(
                "INSERT INTO table2(all the FIELDS)"
                + "VALUES(null, LAST_INSERT_ID(), ...);"          
        );
  
  
        preparedstatement = connect.prepareStatement(
  
                "SELECT id FROM table3 WHERE id = LAST_INSERT_ID();"
  
        );
  
        preparedstatement.executeBatch();
        resultSet = preparedstatement.executeQuery();
  </code></pre>
  
  <p>Get I problems with this implementation or is there an better way?</p>
  
  <p>Best Regards</p>