title: Java MySQL preparedStatement Batch
body: <p>I am trying to use the preparedStatement Batch but I am having a problem.</p>
  
  <p>The following code does not give me errors, but it inserts in the table only last key of the map and I do not know why.</p>
  
  <p>It will be surely a very stupid error, but this is the first time I use the addBatch() method..     </p>
  
  <pre><code>        Class.forName("com.mysql.jdbc.Driver");
          this.connect = DriverManager.getConnection("jdbc:mysql://localhost/" + this.database + "?user=" + this.user + "&amp;password=" + this.password);
          String s;
          for (String key : this.map.keySet())
          {
              s = ("insert into " + this.database + ".user (nickname) values (?)");
              this.preparedStatement = this.connect.prepareStatement(s);
              this.preparedStatement.setString(1, key);
              this.preparedStatement.addBatch();
          }
  
          this.preparedStatement.executeBatch();
  </code></pre>
  
  <p>Thanks in advance!</p>