title: Combine for loop and sql in java
body: <p>I have 2 input dates: <code>myStartDate</code>,<code>myEndDate</code> and a table <code>TEST_TABLE</code> with columns </p>
  
  <pre><code>TEST_ID, TEST_USER,TEST_START, TEST_END
  </code></pre>
  
  <p>I need to check if the range of dates between myStartDate and myEndDate have corresponding records in the TEST_TABLE.
  I also need to ensure that I don't retrieve duplicate records.</p>
  
  <p>Here's a sample of the logic I have so far: </p>
  
  <p>Assuming,</p>
  
  <pre><code>myStartDate=06/06/2012;myEndDate=06/09/2012
  int diff = myEndDate - myStartDate; //In this case = 3
  
  String myQuery = "SELECT * FROM TEST_TABLE WHERE"+ myStartDate +"BETWEEN TEST_START AND TEST_END OR "+ (myStartDate +1) +" BETWEEN TEST_START AND TEST_END OR"+ (myStartDate+2)+"BETWEEN TEST_START AND TEST_END OR"+(myStartDate+3)+"BETWEEN TEST_START AND TEST_END";
  
  List &lt;TestTableData&gt; myList = new List();
  //Exceute query &amp; save results into myList using add method
  </code></pre>
  
  <p>Want to know if there's any way to test the range of dates between myStartDate &amp;myEndDate using a <code>for loop</code> in java code, instead of the approach used above in <code>myQuery</code>.Also, how can I avoid duplicates.</p>
  
  <p>New to Java so any help would be appreciated!</p>