title: multiple threads to insert data in MySQL
body: <p>I want to insert multiple records simultaneously in a table from various threads whith this code. But only half of threads works, for the rest shows: Error: Duplicate entry ' ' for key 'PRIMARY'</p>
  
  <pre><code> final Connection con=MyConnection.connect();
           try{
              con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
              con.setAutoCommit(false);
           }catch (Exception e) { System.out.println("Error: " + e.getMessage()); }
              Thread[] threads = new Thread[50];
               for (int i = 0; i &lt; threads.length; i++) {
                   threads[i] = new Thread(new Runnable() {
                       public void run() {
                              try{
                                  int idr=0; 
                                      Statement st = con.createStatement();
                                      ResultSet rs1 = st.executeQuery("SELECT max(id) FROM employee;");
                                      rs1.next();
                                      idr = rs1.getInt(1)+1;
                                     st.executeUpdate("insert into employee(id,name,address) values('"+idr+"','"+ name+"','"+adrress+"');");
                                     con.commit(); 
                              } catch (Exception e) { System.out.println("Error: " + e.getMessage()); }
                            }
                   });
                   threads[i].start();
               }
  </code></pre>