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.begin()
connection.remove().statements(iri(ex, "Margharita"), null, null) 
connection.commit()

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

Hi,

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 = ConnectionConfiguration.to("myDb")
            .server("http://localhost:5820")
            .credentials("admin", "admin")
            .connect()) {

            c.begin();
            c.update("delete data {graph <http://gra.ph> {:a :b :c}}").execute();
            c.commit();
        }

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