I am a completely beginner to sparql. my problem is that I don't know even where I have to write the sparql queries. (for example for writing java code or RDF we can use eclipse), but I don't know how to start with Sparql( I used this tutorial http://jena.apache.org/tutorials/sparql.html but here I couldn't find where I have to write these queries).


asked 27 Jul '12, 10:27

monmon's gravatar image

accept rate: 0%

For a code specific tutorial you want to look at the ARQ documentation which is Jena's SPARQL processor

That covers how to execute queries in code whereas the documentation you linked only covers executing queries on the command line


I updated the documentation page you linked so it more clearly points users who know SPARQL and want to run queries in code to the ARQ documentation

permanent link

answered 27 Jul '12, 12:21

Rob%20Vesse's gravatar image

Rob Vesse ♦
accept rate: 29%

edited 27 Jul '12, 12:25

Assuming you are using Eclipse to edit your Java project. So, if you wanna run SPARQL query, first, you need kind of SPARQL processor, like ARQ, on the java build path. Then, obviously, you need write SPARQL query. there are two ways, i know so far.

Solution 1: To write query directly in your java code, like:

StringBuffer queryStr=new StringBuffer();
//Establish Prefixes
queryStr.append("PREFIX people"+": <"+"http://xmlns.com/foaf/0.1/1"+"> ");
//Now add query
queryStr.append("select * where {your query statement}");
Query query=QueryFactory.createExecutionFactory.create(query.toString());
QueryExecution qexect=QueryExecutionFactory.create(query,_model);

Solution 2: To wirte the SPARQL queries you need in a *.txt file under your java project, then you can use java method to call the specific query to execute according to the given query name. The details you can find in Pellet-->examples-->src, where there are many basic query examples, I think, will be helpful to you .(Of course, you can find lots of useful information in other places)

Hope the above answer is helpful to you.

permanent link

answered 27 Jul '12, 22:07

W.T%20Zhou's gravatar image

W.T Zhou
accept rate: 0%

Using the first example from http://jena.apache.org/tutorials/sparql_query1.html in the tutorial you point to, you write the query in the file passed as the --query parameter to the sparql.bat batch file. In that particular example, you would write the query (or include the query shown in the tutorial) in the file docTutorialq1.rq, and then the following command runs that query against data stored in the file docTutorialvc-db-1.rdf (assuming that you've set the ARQROOT environment variable as the tutorial also describes):

  batsparql.bat --data=docTutorialvc-db-1.rdf --query=docTutorialq1.rq

permanent link

answered 28 Jul '12, 15:40

bobdc's gravatar image

accept rate: 15%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 27 Jul '12, 10:27

question was seen: 5,039 times

last updated: 02 Nov '12, 08:44