Thanks to Andy and AI, I added timeout parameter to queryexecution, and it works now~
I ran the query on the webpage http://dbpedia.org/sparql without prefix, it worked, so I thought maybe it can be omitted, thanks for reminding me~~ All the best June 2011/7/10 Andy Seaborne <[email protected]> > > > On 09/07/11 00:06, 朱曼 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? >> > > Usually a timeout at DBpedia. > > > >> try { >> Model dbpedia_model = ModelFactory.**createDefaultModel(); >> String queryStr = "SELECT distinct ?c WHERE { ?c a owl:Class >> }"; >> Query query = QueryFactory.create(queryStr); >> > > This is not the code you are running - that would lead to a parse error at > this point. owl: is not defined. > > > query.addGraphURI("http://**dbpedia.org/<http://dbpedia.org/> >> "); >> > > This is the same as adding FROM to the query. You do not use it for > DBpedia. Remove this. > > > 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 >> >> > Works for me: > > > try { > Model dbpedia_model = ModelFactory.**createDefaultModel(); > String queryStr = "select distinct ?Concept where {[] a ?Concept} LIMIT > 10"; > > Query query = QueryFactory.create(queryStr); > QueryExecution qexec = QueryExecutionFactory.**sparqlService(" > http://dbpedia.**org/sparql <http://dbpedia.org/sparql>", query); > // Set the DBpedia specific timeout. > ((QueryEngineHTTP)qexec).**addParam("timeout", "10000") ; > > ResultSet rs = qexec.execSelect(); > ResultSetFormatter.out(System.**out, rs, query); > qexec.close(); > } catch (Exception e) { > e.printStackTrace(); > } > > Andy > >
