title: Passing an array to SELECT * FROM table WHERE country IN (?...)
body: <p>Is there a way to pass an array of strings for a "WHERE country IN (...)" query?</p>
  
  <p>something like this:</p>
  
  <pre><code>String[] countries = {"France", "Switzerland"};
  PreparedStatement pstmt = con.prepareStatement("SELECT * FROM table WHERE country IN (?...)");
  pstmt.setStringArray(1, countries);
  pstmt.executeQuery();
  </code></pre>
  
  <p>an ugly workaround would be to create the query based on the size of the array</p>
  
  <pre><code>String[] countries = {"France", "Switzerland"};
  if (countries.size() == 0) { return null; }
  String query = "SELECT * FROM table WHERE country IN (?";
  for (int i = 1; i &lt; countries.size; i++) { query += ", ?"; }
  PreparedStatement pstmt = con.prepareStatement(query);
  for (int i = 0; i &lt; countries.size; i++) { pstmt.setString(1+i, countries[i]); }
  pstmt.executeQuery();
  </code></pre>
  
  <p>but this looks really ugly.</p>
  
  <p>any idea?</p>