1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
   |  
try{
			String queryString =	"SELECT  ?label ?comment " + " WHERE { " +
                                     "<"+uri2+">  <http://www.w3.org/2000/01/rdf-schema#label> ?label." +
					"<"+uri2+">  <http://www.w3.org/2000/01/rdf-schema#comment> ?comment." +
					"  FILTER langMatches(lang(?label), 'en') " +
					"  FILTER langMatches(lang(?comment), 'en')}";
			Query query = QueryFactory.create(queryString);
			// initializing queryExecution factory with remote service.
			// **this actually was the main problem I couldn't figure out.**
			QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
 
			try {
				ResultSet results = qexec.execSelect();
			    for (; results.hasNext();) {
			    	QuerySolution sol = results.next();
                                if (sol.get("?label")!= null ){
                                vnom2.addElement(sol.get("?label"));}
                                else vnom2.addElement(" ");
 
                                if (sol.get("?label")!= null ){
 
                                vlabel2.addElement(sol.get("?label"));}
                                else vlabel2.addElement("");
 
                                if (sol.get("?comment")!= null){
 
                              vcomment2.addElement(sol.get("?comment"));
 
                            }
                                else vcomment2.addElement("");
 
 
                            }
			}catch(Exception e1){
				e1.printStackTrace();
			}
			finally {
			   qexec.close();
			}
 
    	}catch(Exception e1){
    		e1.printStackTrace();
    	}
                         }
                    } | 
Partager