Hi, Check out SPARQL query syntax http://www.w3.org/TR/rdf-sparql-query/
-----Original Message----- From: Nallanchakravarthy Ramadurai Ananthanarayanan [mailto:[email protected]] Sent: 19 January 2012 10:37 To: [email protected] Subject: ERROR IN SPARQL Query package QueryBuilder; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSetFormatter; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; public class Query4 { public static void main(String[] args) throws IOException { InputStream in = new FileInputStream(new File("d:/PROJECT/vc-db-1.rdf")); // Create an empty in-memory model and populate it from the graph Model model = ModelFactory.createMemModelMaker().createDefaultModel(); model.read(in,null); // null base URI, since model URIs are absolute in.close(); // Create a new query String queryString= "{<http://www.w3.org/2001/vcard-rdf/3.0#> SELECT ?g WHERE { ?y Given ?g . FILTER regex(?g, 'r', 'i')}}"; Query query = QueryFactory.create(queryString); // Execute the query and obtain results QueryExecution qe = QueryExecutionFactory.create(query, model); ResultSet results = qe.execSelect(); // Output query results ResultSetFormatter.out(System.out, results, query); // Important - free up resources used running the query qe.close(); } } Error ------- Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Encountered " "{" "{ "" at line 1, column 1. Was expecting one of: "base" ... "prefix" ... "select" ... "describe" ... "construct" ... "ask" ... at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:87) at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.parse(ParserSPARQL11.java:40) at com.hp.hpl.jena.query.QueryFactory.parse(QueryFactory.java:132) at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:69) at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:40) at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:28) at QueryBuilder.Query4.main(Query4.java:25)
