title: Java: weird issue with iterator
body: <p>I am having a weird problem with an iterator I don't fully understand.
  The iterator is being used in a loggedPreparedStatement but every now and then (about 20 of the 200) throws this error:</p>
  
  <pre><code>SQLException in executeQuery, errorcode: 0, SQL state: 07001, message: No value specified for parameter 1
  while executing statement: com.mysql.jdbc.PreparedStatement@11fffa73: SELECT ac.id as i FROM ac LEFT JOIN pa ON pa.id = ac.adspace_id WHERE  pa.adspace_id IN (** NOT SPECIFIED **) 
  </code></pre>
  
  <p>This is how I create my iterator:</p>
  
  <pre><code>private Iterator&lt; Integer &gt; adspacesId = null;
  
  public ArrayList&lt;Integer&gt; getIds(int inAdspaceId) {
          if (inAdspaceId &lt;= 0) return new ArrayList&lt;Integer&gt;();
          ArrayList&lt;Integer&gt; tempList = new ArrayList&lt;Integer&gt;();
          tempList.add(new Integer(inAdspaceId));
          adspacesId = tempList.listIterator();
          num = tempList.size();
          activeOnly = false;
  
          if (adspacesId != null &amp;&amp; adspacesId.hasNext() &amp;&amp; num &gt; 0) {
              executeQuery();
          }
          return result;
      }
  </code></pre>
  
  <p>So I add an int to a temp arrayList and then turn that into a Iterator, then use that iterator in my query like so:</p>
  
  <pre><code>LoggedPreparedStatement statement = new LoggedPreparedStatement(theQuery.toString());
  statement.setInt(1, adspacesId);
  </code></pre>
  
  <p>So my first guess would be, no entries in my iterator, but how does it pass the check of adspacesId.hasNext() then?</p>
  
  <p>The value of num is 1, so there is an entry in the templist and I would assume in my iterator.</p>
  
  <p>Little help is welcome :)</p>