Skip to content

Instantly share code, notes, and snippets.

@harschware
Last active December 16, 2015 02:49
Show Gist options
  • Select an option

  • Save harschware/5365165 to your computer and use it in GitHub Desktop.

Select an option

Save harschware/5365165 to your computer and use it in GitHub Desktop.
Code for connecting Sesame to a SPARQL endpoint
package harschware.drivers;
import org.openrdf.model.Statement;
import org.openrdf.model.URI;
import org.openrdf.model.ValueFactory;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.RepositoryResult;
import org.openrdf.repository.sparql.SPARQLRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SesameClientDriver {
public static void main(String[] args) throws RepositoryException {
SPARQLRepository sr = new SPARQLRepository("http://localhost:3030/dataset/sparql");
sr.initialize();
RepositoryConnection conn = sr.getConnection();
ValueFactory vf = conn.getValueFactory();
try {
URI uri = vf.createURI("http://dbpedia.org/ontology/ProgrammingLanguage");
RepositoryResult<Statement> rs = conn.getStatements(uri, null, null, false);
while(rs.hasNext() ) {
Statement s = rs.next();
System.out.println(s);
}
rs.close();
}
finally {
conn.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment