title: SPARQL query against DBPedia using Java
body: <p>I would like to query on DBPedia using Java. Below is my code and it does not return corrrect result.I want to get Abstract part from [<a href="http://dbpedia.org/page/Ibuprofen" rel="nofollow">http://dbpedia.org/page/Ibuprofen</a> page and label name. but it returns only <a href="http://dbpedia.org/resource/Ibuprofen" rel="nofollow">http://dbpedia.org/resource/Ibuprofen</a>  11 times. If possible could you tell me where is the mistake? This is my code:</p>
  
  <pre><code>import org.apache.jena.query.ParameterizedSparqlString;
  import org.apache.jena.query.QueryExecution;
  import org.apache.jena.query.QueryExecutionFactory;
  import org.apache.jena.query.ResultSet;
  import org.apache.jena.query.ResultSetFormatter;
  import org.apache.jena.rdf.model.Literal;
  import org.apache.jena.rdf.model.ResourceFactory;
  
  public class JavaDBPediaExample {
  
      public static void main(String[] args) {
          ParameterizedSparqlString qs = new ParameterizedSparqlString(""
                  + "prefix rdfs:    &lt;http://www.w3.org/2000/01/rdf-schema#&gt;\n"
                  + "PREFIX dbo:     &lt;http://dbpedia.org/ontology/&gt;"
                  + "\n"
                  + "select ?resource where {\n"
                  + "  ?resource rdfs:label ?label.\n"
                  + "  ?resource dbo:abstract ?abstract.\n"
                  + "}");
  
          Literal ibuprofen = ResourceFactory.createLangLiteral("Ibuprofen", "en");
          qs.setParam("label", ibuprofen);
  
          QueryExecution exec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", qs.asQuery());
  
          ResultSet results = exec.execSelect();
  
          while (results.hasNext()) {
  
              System.out.println(results.next().get("resource"));
          }
  
          ResultSetFormatter.out(results);
      }
  }
  </code></pre>