3

I am trying to insert new data to Fuseki through SPARQL query, it's giving me success(200 OK) but it's not showing in my TDB. and I think it's because I haven't defined to which graph but I don't know-how

    String queryString =          
          "PREFIX ns:<http://www.semanticweb.org/hightech/ontologies/2019/unit#>" 
                    + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>" 
                    + "INSERT DATA{" 
                    + "ns:" + d.getDomainName()+ "ns:domainName " + d.getDomainName() + "." 
                    + "ns:" + d.getDomainName() + " ns:domainId "+ d.getDomainId() + "." 
                    + "}";

            UpdateRequest request = UpdateFactory.create(queryString);
            UpdateProcessor qe = UpdateExecutionFactory.createRemote(request,
                    "http://localhost:3030/eduDataSet/update");
            qe.execute();
        
H. H
  • 103
  • 9
  • 1
    how do you check if it's not in the database? I also suggest to use `RDFConnection` nowadays: https://jena.apache.org/documentation/rdfconnection/ – UninformedUser Nov 04 '20 at 08:22
  • 1
    you can do `select * where {{graph ?g {?s ?p ?o}} union {?s ?p ?o }}` to see if any data is in the database – UninformedUser Nov 04 '20 at 08:23
  • I check using query on Fuseki UI direct. I think my problem is the insert sparql query format. would rdfconnection solve that, can you give an example? – H. H Nov 04 '20 at 09:08
  • 1
    so, did you run the query I posted? What is the result of it? Also, your namespace declaration is a bit odd, i.e. `PREFIX ns:` - please use proper URIs. – UninformedUser Nov 04 '20 at 09:22
  • An example is given in the link I posted, see paragraph "Update Usage" there. Might not solve your problem, but it's the better way to go when using Jena nowadays I guess. – UninformedUser Nov 04 '20 at 09:23
  • @UninformedUser I edited the prefix. and the query result is all the graph – H. H Nov 04 '20 at 16:14
  • MY question was more, is your inserted data in the returned resultset or not? – UninformedUser Nov 04 '20 at 17:05
  • What's the configuration of "http://localhost:3030/eduDataSet/" because if it has "unionDefaultGraph true" then you wil see you data in a query because it is not in a named graph. Try `select * where {graph { ?s ?p ?o }}` or add `GRAPH { .... }` to the data part of `INSERT DATA` or remove the "unionDefaultGraph true". – AndyS Nov 06 '20 at 15:39

1 Answers1

2

try to reformat your queryString as shown in this picture.

enter image description here

reference

be careful where to close your subject
"PREFIX ns:<http://www.semanticweb.org/hightech/ontologies/2019/unit#>" <== is already closed, while you need to insert your d.getDomainName() before closing ">"

fatmasiraj
  • 60
  • 1
  • 6
  • I tried to do it like this example ` "INSERT DATA{" + "<"+ OntologyManagerWithFusekiApplication.ns + d.getDomainId() + "> ns:domainName \""+ d.getDomainName() + "\"." + "<"+ OntologyManagerWithFusekiApplication.ns + d.getDomainId() + "> ns:domainId \"" + d.getDomainId() + "\"." + "}"; ` but still not working, lexical syntax error – H. H Nov 04 '20 at 22:45
  • 1
    try this one : "INSERT DATA{" + "<" + OntologyManagerWithFusekiApplication.ns + d.getDomainId() + "> ns:domainName \""+ d.getDomainName() + "\";" + "ns:domainId \"" + d.getDomainId() + "\"." + "}"; – fatmasiraj Nov 04 '20 at 22:54