Parameterized SPARQL query with JENA
Posted
by
sandra
on Stack Overflow
See other posts from Stack Overflow
or by sandra
Published on 2012-03-15T23:21:01Z
Indexed on
2012/07/05
3:16 UTC
Read the original article
Hit count: 239
I'm trying to build a small semantic web application using Jena framework, JSP and JAVA. I have a remote SPARQL endpoint and I've already written a simple query which works fine but now I need to use some parameters. Here is my code so far:
final static String serviceEndpoint = "http://fishdelish.cs.man.ac.uk/sparql/";
String comNameQuery =
"PREFIX fd: <http://fishdelish.cs.man.ac.uk/rdf/vocab/resource/> " +
"SELECT ?name ?language ?type" +
"WHERE { ?nameID fd:comnames_ComName ?name ;" +
"fd:comnames_Language ?language ;" +
"fd:comnames_NameType ?type ." +
"}";
Query query = QueryFactory.create(comNameQuery);
QueryExecution qe = QueryExecutionFactory.sparqlService(serviceEndpoint,query);
try {
ResultSet rs = qe.execSelect();
if ( rs.hasNext() ) {
System.out.println(ResultSetFormatter.asText(rs));
}
}
catch(Exception e) {
System.out.println(e.getMessage());
}
finally {
qe.close();
}
What I want to do is to parameterized ?name. I'm new to Jena and I'm not really sure how to use parameters in a SPARQL query. I would appreciate it if someone could help me with this.
© Stack Overflow or respective owner