title: Insert to database a lot of data with batch insert
body: <p>I create a program that inserts to MySql database millions of values. 
  I read about batch insert that will optimize my program and make it faster but when I tried to do it, it worked in the same way.
  Instead of inserting each value to the database I kept in a list each time 500 values and then insert them in one big loop like this:</p>
  
  <pre><code>for(int i=0;i&lt;500;i++)
  {
     insertData(list.get(i));
  }
  </code></pre>
  
  <p>Then i remove all the values in the list and start collecting 500 values again.
  Shouldn't it work better?<br>
  My Insert code is:</p>
  
  <pre><code>public void insertToNameTable(String id,String name) throws SQLException
         {
             PreparedStatement ps=null;
  
              ps= conn.prepareStatement("INSERT INTO NameTable values(?,?,?)",user.getId(),user.getName());
  
  
              ps.setString(1,id);
              ps.setString(2,name);
              ps.setBoolean(3,false);
              ps.executeUpdate();
  
         }
  </code></pre>
  
  <p>I have some questions:<br>
  1.why it isn't work faster when i do batch insert?<br>
  2.how many values I should enter each time in order to make it faster?(500,1000,10000) the more values enter together is better?<br>
  3. is the way I insert the values to my database is the best way?<br></p>