• Topic
  • Discussion
  • VOS.VirtJenaSPARQLExample10(Last) -- DAVWikiAdmin? , 2017-06-13 05:40:15 Edit WebDAV System Administrator 2017-06-13 05:40:15

    Virtuoso Jena Provider - SPARQL Example 10


    import com.hp.hpl.jena.query.*;
    import com.hp.hpl.jena.rdf.model.RDFNode;
    
    import virtuoso.jena.driver.*;
    
    public class VirtuosoSPARQLExample10 {
    
    	/**
    	 * Executes a SPARQL query against a virtuoso url and prints results.
    	 */
    	public static void main(String[] args) {
    
    		String url;
    		if(args.length == 0)
    		    url = "jdbc:virtuoso://localhost:1111";
    		else
    		    url = args[0];
    
    /*			STEP 1			*/
    		VirtGraph set = new VirtGraph ("gr", url, "dba", "dba");
    
    /*			STEP 2			*/
    
    
    /*			STEP 3			*/
    /*		Select all data in virtuoso	*/
    		String query = "SELECT * WHERE { ?s ?p ?o } limit 100";
    
    /*			STEP 4			*/
    		QueryExecution vqe = VirtuosoQueryExecutionFactory.create (query, set);
    
    		ResultSet results = vqe.execSelect();
    		while (results.hasNext()) {
    			QuerySolution result = results.nextSolution();
    		    RDFNode graph = result.get("graph");
    		    RDFNode s = result.get("s");
    		    RDFNode p = result.get("p");
    		    RDFNode o = result.get("o");
    		    System.out.println(graph + " { " + s + " " + p + " " + o + " . }");
    		}
    	}
    }