How to execute a delete query via java?

I want to delete every triple having a given subject but only if the subject is of a given type. The following query works as expected:

delete {?s ?p ?o} where {
    ?s ?p ?o.
    ?s a ex:Pizza
    filter(?s = ex:Margharita)

How can I do that using the java API ? I tried the Remover but I can’t find a way to filter the triples :

connection.remove().statements(iri(ex, "Margharita"), null, null) 

And I can’t execute the query using nor Connection.update
Can anyone tell me the proper way to do that ?


Connection.update() should do the trick for you. The only gotcha I can see is that update() returns an UpdateQuery object, on which you need to call execute():

try (Connection c ="myDb")
            .credentials("admin", "admin")
            .connect()) {

            c.update("delete data {graph <> {:a :b :c}}").execute();

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.