开发者

Querying TDB from Java returning nothing

I am trying to query a TDB database that has a few entries of RDF from a DBpedia dataset for testing, later on it will have much more entries. I am using a suggestion found in How to use Jena TDB to store local version of Linked Movie Database but the program returns nothing.

public static void main(String[] args) throws Exception {
    String directory = "C:\\Users\\MyPC\\Fuseki\\Fuseki-0.2.0\\mydatasets";
    Dataset dataset = TDBFactory.createDataset(directory);
    Model model = dataset.getDefaultModel();

    String queryString = "SELECT * WHERE { ?s ?p ?o }";
    Query query = QueryFactory.create(queryString);
    QueryExecution qexec = QueryExecutionFactory.create(query, model);
    try {
        ResultSet results = qexec.execSelect();
        for (; results.hasNext();) {
            QuerySolution soln = results.nextSolution();
            System.out.println(soln);
            RDFNode x = soln.get("varName");       // Get a result variable by name.
            Resource r = soln.getResource("VarR"); // Get a result variable - must be a resource
            Literal l = soln.getLiteral("VarL");   // Get a result variable - must be a literal
        }
    } catch (Exception e) {
        System.err.print("Error:"+e.getMe开发者_如何学运维ssage());
    } finally {
        qexec.close();
    }
}

When the debugger gets to the for for (; results.hasNext();) { loop it just skips the try block and gets to qexec.close() at the bottom. I know I have data in the store because from Fuseki I can do the same query and get all the rows of data.

Can someone please point me in the right direction to some sort of solution? I have tried different methods without success.


Sounds like you have no results. Try adding:

System.err.printf("Model size is: %s\n", model.size);

to see how large the model is: I suspect the answer is 0.

How did you load the data? Are you sure C:\\Users\\MyPC\\Fuseki\\Fuseki-0.2.0\\mydatasets is the right location?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜