Querying SPARQL endpoints using Jena JDBC and Squirrel SQL

My favorite SQL Editor is Aqua Datastudio, which I use for Open Source projects, accessing Hive, MySQL, SQLite and several other data bases. However, while working on a customer site, I can’t use Datastudio due to its license. So another great SQL Editor that I use is Squirrel SQL.

Last week I had to execute several queries manually against a SPARQL endpoint - that was using Fuseki BTW. After doing that for ten minutes I decided that I needed a more productive way. Here’s where Jena JDBC enters.

Preparing your environment

In order to query a SPARQL endpoint, the first thing you need is a SPARQL endpoint. For this experiment, let’s use the myExperiment public SPARQL endpoint. myExperiment is used for sharing workflows, and I’ve been studying it to use in BioUno.

We will also need a SPARQL query. Let’s use the following simple and intuitive query, limiting to 10 results.

    WHERE {
        ?s ?p ?o

You will also need to download:

Configuring Squirrel SQL

You probably already have Squirrel SQL installed at this point. If not, download the jar and run java -jar squirrel*.jar. And you may have been tempted to check all the plug-ins during the installation. The problem is that the SQL Parametrisation plug-in will think that the ?s ?p ?o are variables, and will keep popping a dialog for you to input values.

So disable the SQL Parametrisation plug-in by going to Plugins / Summary and unchecking it.

Copy the Jena JDBC bundle jar to $SQUIRREL_HOME/lib/, and go to the Drivers tab, probably on your left, and add a JDBC driver for Jena JDBC. Give it any name you like. As example URL you can use jdbc:jena:remote:query=http://localhost:3030/ds/query&update=http://localhost:3030/ds/update. And the class name, for remote endpoints, is org.apache.jena.jdbc.remote.RemoteEndpointDriver.


Finally, add a new connection, by going to the Aliases tab - again, probably on your left - and selecting the Jena driver that you just created. Give it some cool name, select the Jena driver, and for the connection URL use jdbc:jena:remote:query=http://rdf.myexperiment.org/sparql. Save it and you are ready to rock.


Your first SPARQL query using JDBC

By double clicking the connection alias and confirming that you want to connect (leave user and pass empty) Squirrel SQL should give a screen where you can enter SQL commands. Enter any SPARQL query and give it a shot. Here’s my result.


Happy hacking!