69776

example of stardog sparql insert query in java

Question:

Can somebody give one java example of sparql insert/Delete query in Stardog.

there is only queryExecution.execSelect() method available. there is no queryExecution.execInsert() or queryExecution.execDelete() available. Please give one working example.

<strong>EDIT</strong>

I've found this this from stardog docs page.

<a href="http://stardog.com/docs/#notes" rel="nofollow">http://stardog.com/docs/#notes</a>

<strong>As of 1.1.5, Stardog's SPARQL 1.1 support does not include: UPDATE query language</strong>

does that means no way out for editing a tuple once entered?

Answer1:

Stardog does not yet support SPARQL update, but as was pointed out to you on the mailing list, there are 5 ways you can modify the data once it's loaded. You can use our HTTP protocol directly, any of the 3 Java API's we support, or you can use the command line interface.

Answer2:

Below one is a sample program of inserting a graph and removing it.

package com.query; import java.util.List; import org.openrdf.model.Graph; import org.openrdf.model.Statement; import org.openrdf.model.URI; import org.openrdf.model.impl.GraphImpl; import org.openrdf.model.impl.ValueFactoryImpl; import org.openrdf.query.QueryEvaluationException; import com.clarkparsia.stardog.StardogDBMS; import com.clarkparsia.stardog.StardogException; import com.clarkparsia.stardog.api.Connection; import com.clarkparsia.stardog.api.ConnectionConfiguration; import com.clarkparsia.stardog.jena.SDJenaFactory; import com.hp.hpl.jena.query.ParameterizedSparqlString; import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSetFormatter; import com.hp.hpl.jena.rdf.model.Model; public class test { public static void main(String[] args) throws StardogException, QueryEvaluationException { String appDbName ="memDb"; String selectQuery="SELECT DISTINCT ?s ?p ?o WHERE { ?s ?p ?o }"; StardogDBMS dbms = StardogDBMS.toServer("snarl://localhost:5820/") .credentials("admin", "admin".toCharArray()).login(); List<String> dbList = (List<String>) dbms.list(); if (dbList.contains(appDbName)) { System.out.println("droping " + appDbName); dbms.drop(appDbName); } dbms.createMemory(appDbName); dbms.logout(); Connection aConn = ConnectionConfiguration .to("memDb") // the name of the db to connect to .credentials("admin", "admin") // credentials to use while connecting .url("snarl://localhost:5820/") .connect(); Model aModel = SDJenaFactory.createModel(aConn); System.out.println("################ GRAPH IS EMPTY B4 SUBMITTING ="+aModel.getGraph()+ "################"); URI order = ValueFactoryImpl.getInstance().createURI("RDF:president1"); URI givenName = ValueFactoryImpl.getInstance().createURI("RDF:lincoln"); URI predicate = ValueFactoryImpl.getInstance().createURI("RDF:GivenNane"); Statement aStmt = ValueFactoryImpl.getInstance().createStatement(order,predicate,givenName); Graph aGraph = new GraphImpl(); aGraph.add(aStmt); insert(aConn, aGraph); ParameterizedSparqlString paraQuery = new ParameterizedSparqlString(selectQuery); QueryExecution qExecution = QueryExecutionFactory.create(paraQuery.asQuery(),aModel); ResultSet queryResult = qExecution.execSelect(); System.out.println("############### 1 TUPPLE CAME AFTER INSERT ################"); ResultSetFormatter.out(System.out, queryResult); aGraph.add(aStmt); remove(aConn, aGraph); paraQuery = new ParameterizedSparqlString(selectQuery); qExecution = QueryExecutionFactory.create(paraQuery.asQuery(),aModel); queryResult = qExecution.execSelect(); System.out.println("################ DB AGAIN EMPTY AFTER REMOVE ################"); ResultSetFormatter.out(System.out, queryResult); System.out.println("closing connection and model"); aModel.close(); aConn.close(); } private static void insert(final Connection theConn, final Graph theGraph) throws StardogException { theConn.begin(); theConn.add().graph(theGraph); theConn.commit(); } private static void remove(final Connection theConn, final Graph theGraph) throws StardogException { theConn.begin(); theConn.remove().graph(theGraph); theConn.commit(); } }

Recommend

  • curl - How to escape < in parameter value
  • K Shortest Path Python Not Working
  • Rely on Facebook user id as a permanent user identifier
  • Making Cross Site Asynchronous HTTP Post from GWT Client
  • CKeditor stripping font tags instead of converting to span
  • How to add learning rate to summaries?
  • Changing media screen makes div overlay
  • Double dispatch in Java example
  • ckeditor and jquery UI dialog not working
  • .NET video play library which allows to change the playback rate?
  • Android Database Error - getWriteableDatabase
  • Using Generics on right hand side in Java 6?
  • How to 'create temp table as select' in Slick?
  • How can I tell a form not to dispose a particular control when it closes?
  • SonarQube: Cannot deactivate rule with missing quality profile
  • where do I find the xml.dom python package for the python-2.6.0-8.9.28 and I have a suse/x86_64 vers
  • Spring boot 2.0.0.M4 required a bean named 'entityManagerFactory' that could not be found
  • Remove changes from one element when event occurs on another element?
  • Read text file that is not in the main package in a runnable jar
  • Roxygen error “Skipping invalid path”
  • What is the purpose of TaskExecutor in spring?
  • how to find common suffix in java by using method
  • MySQL Order by column = x, column asc?
  • Remove final comma from string in vb.net
  • ImageMagick, replace semi-transparent white with opaque white
  • Cannot connect to cassandra from Spark
  • Cross-Platform Protobuf Serialization
  • Weird JavaScript statement, what does it mean?
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • Why winpcap requires both .lib and .dll to run?
  • Return words with double consecutive letters
  • Python: how to group similar lists together in a list of lists?
  • Turn off referential integrity in Derby? is it possible?
  • Add sale price programmatically to product variations
  • Busy indicator not showing up in wpf window [duplicate]
  • Binding checkboxes to object values in AngularJs
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app
  • git trying to push non-existent file … after clearing cache
  • How do I use LINQ to get all the Items that have a particular SubItem?