简体   繁体   中英

sparql query in java

I am writing a sparql query in java to select all records with a specific title. I am trying with this query

SELECT * WHERE { ?title rdf:type ?specific_title .}    

but it doesn't work. Does anyone know which is my mistake? Thanks

java.lang.IndexOutOfBoundsException: Index: 3, Size: 3

It sounds to me like you are trying to iterate over the resultset and you are requesting a row that doesn't exist. Are you using Jena? If you are, it should simply be a case of:

if (ResultSet.hasNext()) {
    ResultSet.next();
    QuerySolution nextResult = ResultSet.nextSolution();
}

Can you show us an example of the data that you are running this query over?

Have you defined the rdf prefix (namespace) at the start of your query.

Also note that the value of an rdf:type property should be an rdfs:Class represented by its URI, eg

PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
PREFIX ex: http://www.example.com#
SELECT ?x WHERE { ?x rdf:type ex:ExampleClass }  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM