Your SPARQL query needs to declare the prefix for OWL:

PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT distinct ?c ?p WHERE { ?c a owl:Class } LIMIT 10

Also for this query you don't need the "addGraphURI" or the Model since you
are using QueryExecutionFactory.sparqlService

See here for some commentary on it:
http://linkedjava.blogspot.com/2011/06/two-ways-to-query-linked-data-with-arq.html

Here is a gist with this query working:

https://gist.github.com/1073737

Al


On Fri, Jul 8, 2011 at 7:06 PM, 朱曼 <[email protected]> wrote:

> Dear list,
>
> hi~~
>
> I encounter "HttpException: java.net.SocketException: Connection reset:
> java.net.SocketException: Connection reset" exception when I run the
> following code, could you help me?
>
>        try {
>            Model dbpedia_model = ModelFactory.createDefaultModel();
>            String queryStr = "SELECT distinct ?c WHERE { ?c a owl:Class }";
>            Query query = QueryFactory.create(queryStr);
>            query.addGraphURI("http://dbpedia.org/";);
>            QueryExecution qexec = QueryExecutionFactory.sparqlService("
> http://dbpedia.org/sparql";, query);
>            ResultSet rs = qexec.execSelect();
>            ResultSetFormatter.out(System.out, rs, query);
>            qexec.close();
>        } catch (Exception e) {
>            e.printStackTrace();
>        }
>
> all the best
>
> June
>

Reply via email to