title: SQL : how to use IN keyword with prepared statement for range replacement using Java
body: <pre><code>String sql = "select * from file_repo_index where id in (?)";
  
  PreparedStatement ps = conn.prepareStatement(sql);
  
  ps.setString (1, toCommaSeparatedList(repoIdList));     
  
  ResultSet result = ps.executeQuery();
  </code></pre>
  
  <hr>
  
  <pre><code>public static String toCommaSeparatedList(Collection col);
  </code></pre>
  
  <hr>
  
  <p>I have to use the query as </p>
  
  <pre><code>select * from file_repo_index where id in ( 1,2,3,4 )
  </code></pre>
  
  <p>But it gives following error in executeQuery() statement</p>
  
  <p>java.sql.SQLException: Conversion failed when converting the nvarchar value '213304,213305,213307' to data type int.</p>
  
  <p>I can use it like </p>
  
  <pre><code>String sql = "select * from file_repo_index where id in ("+toCommaSeparatedList(repoIdList)+")";
  
  Statement ps = conn.createStatement();
  
  ResultSet result = ps.executeQuery(sql);
  </code></pre>
  
  <p>But I want to use the PrepareStatment method. How can I do it. ?? </p>