title: Mysql custom auto increment id to fix random ids
body: <p>I have joined a project which has used client side generated random numbers for primary key fields within a mysql database. These primary key fields are auto-increment, but have not been used as such.</p>
  
  <p>I think this was done because the developer did not know how to retrieve the database generated id after insertion.</p>
  
  <p>We now have a sparse array of id values in many tables and a significant number of key collisions on insertion.</p>
  
  <p>Is there some remedial work I can do to allow the database to generate the ids (i.e. start from the last allocated id and find the next available id) and for the following JDBC call to work?</p>
  
  <pre><code>numero = stmt.executeUpdate(query, Statement.RETURN_GENERATED_KEYS);
  </code></pre>