Reputation: 1
I'm trying to delete all triples, I have these functions,
class variables
public static String defaultNameSpace = "http://www.semanticweb.org/admin/ontologies/2016/3/Inventory#";
public Model Inventario = null;
public Model schema = null;
public String DatabaseFile = "PR2INVENTARIORDFXML.owl";
public OutputStream output;
public ResultSet runQuery(String queryRequest, Model model)
{
StringBuffer queryStr = new StringBuffer();
ResultSet response = null;
// Establish Prefixes
//Set default Name space first
queryStr.append("PREFIX base: <" + defaultNameSpace + "> ");
queryStr.append("PREFIX rdfs: <" + "http://www.w3.org/2000/01/rdf-schema#" + "> ");
queryStr.append("PREFIX rdf: <" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#" + "> ");
queryStr.append("PREFIX owl: <http://www.w3.org/2002/07/owl#>");
//Now add query
queryStr.append(queryRequest);
Query query = QueryFactory.create(queryStr.toString());
QueryExecution qexec = QueryExecutionFactory.create(query, model);
try
{
response = qexec.execSelect();
}
finally { }
return response;
}
I have functions for each query, here is an example
public ResultSet AllRecords(Model model)
{
return runQuery("select ?s ?p ?o where{?s ?p ?o."
+ "} " , model);
}
When I try to run these queries
public ResultSet BorrarPC(Model model)
{
return runQuery("DELETE {base:PC1 ?p ?o} " +
"WHERE {base:PC1 ?p ?o}" +
"" , model);
}
public ResultSet eraseAllTriples(Model model)
{
return runQuery("DELETE {?s ?p ?o} " +
"WHERE {?s ?p ?o}" +
"" , model);
}
It gives me these error
run:
Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Encountered " "delete" "DELETE "" at line 1, column 233. Was expecting one of: "prefix" ... "select" ... "describe" ... "construct" ... "ask" ...
at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:87)
at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.parse(ParserSPARQL11.java:40)
at com.hp.hpl.jena.query.QueryFactory.parse(QueryFactory.java:132)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:69)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:40)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:28)
at explorerowlexample.FinalProject.runQuery(FinalProject.java:146)
at explorerowlexample.FinalProject.BorrarPC(FinalProject.java:90)
at explorerowlexample.FinalProject.main(FinalProject.java:56)
Java Result: 1 BUILD SUCCESSFUL (total time: 5 seconds)
How to create a delete statement?
Upvotes: 0
Views: 527
Reputation: 16700
A SPARQL Update request is not a query.
You need to use the update API: See UpdateExecutionFactory
.
Upvotes: 3