title: Enter values from a list into a sparql query
body: <p>I have the following code:</p>
  
  <pre><code> public static List getSomeReceipes(List ing){
      List list = new ArrayList();
  
      String log4jConfPath = "C:/Users/Karen/workspace/Jena/src/Tutorial/log4j.properties";
      PropertyConfigurator.configure(log4jConfPath);
      String ingre = " ";
  
      try {
          //opening owl file
          Model model = ModelFactory.createDefaultModel();
          model.read(new FileInputStream("C:/Users/Karen/Desktop/Proyecto/bbdd.owl"), null, "TTL");
          //System.out.println(model);
          for(int i=0; i&lt;ing.size(); i++){
              ingre = (String) ing.get(i);
              System.out.println(ingre);
          }
          //create a new query
                   String queryString
                  ="PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;"
                  +"PREFIX owl: &lt;http://www.w3.org/2002/07/owl#&gt;"
                  +"PREFIX rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt;"
                  +"PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;"         
                  +"PREFIX rec:&lt;http://www.receta.org#&gt;"
                  +"SELECT reduced ?r WHERE { "
                  +"  ?x rdf:type rec:Receta . "
                  +"  ?x rdfs:label ?r."
                  +"  filter not exists {"
                  +"    ?x rec:Ingrediente ?i"
                  +"    filter( ?i not in (rec:" + ing + "))"
                  +"}"
                  +"}";
          com.hp.hpl.jena.query.Query q = QueryFactory.create(queryString);
  
          //execute the query and obtain results
  
          QueryExecution qe = QueryExecutionFactory.create(q, model);
          ResultSet results = qe.execSelect();
  
          //print query results
          while (results.hasNext()) {
              //System.out.println(results.getResourceModel());
              //ResultSetFormatter.out(System.out,results, q);
              list.add(results.next());
          }
      } catch (java.lang.NullPointerException e) {
          System.out.println(e);
      } catch (Exception e) {
          //System.out.println("Query Failed !");
      }
       System.out.println(list.toString() + "\n");
          return list;      
  }
  </code></pre>
  
  <p>I would like to add every element of the list given (ing) into the query. So lets say I have a list like: ing=[Tomato, Cucumber, Salt] The I would like to create a query like this:</p>
  
  <pre><code>                 String queryString
                  ="PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;"
                  +"PREFIX owl: &lt;http://www.w3.org/2002/07/owl#&gt;"
                  +"PREFIX rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt;"
                  +"PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;"         
                  +"PREFIX rec:&lt;http://www.receta.org#&gt;"
                  +"SELECT reduced ?r WHERE { "
                  +"  ?x rdf:type rec:Receta . "
                  +"  ?x rdfs:label ?r."
                  +"  filter not exists {"
                  +"    ?x rec:Ingrediente ?i"
                  +"    filter( ?i not in (rec:" + Tomato + ", rec:" + Cucumber + ", rec:" + Salt + "))"
                  +"}"
                  +"}";
  </code></pre>
  
  <p>Is there anyway to do that? Any ideas?</p>