Search code examples
javainsertsparqljenaapache-jena

Jena Fuseki Sparlql INSERT and DELETE in java


I am using the apache jena sparql api to communicate with a remote jena fuseki server using the uri as in the uri: http://localhost:3030/Test. I would like to preform sparql insert and delete queries in addition to select. Here is my code for select queries:

private String serviceURI =  "http://localhost:3030/Test";
    /**
     * This method prints the result of a sparql query as table
     * @param Query to get the result of
     */
    public void printSparqlResult(String query){
        QueryExecution q = QueryExecutionFactory.sparqlService(this.serviceURI,query);
        ResultSet results = q.execSelect(); // get result-set
         ResultSetFormatter.out(System.out, results); // print results
    }

Solution

  • SPARQL Query and SPARQL Update are different languages

    Use UpdateExecutionFactory to create an execution of a SPARQL Update.

    The endpoint will not be "http://localhost:3030/Test" -- more likely "http://localhost:3030/Test/update". The query service is /Test/query though directly on the dataset usually works.