1

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.getMessage());
    } 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.

Community
  • 1
  • 1
salvu
  • 519
  • 5
  • 14

1 Answers1

4

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?

user205512
  • 8,798
  • 29
  • 28
  • I found my problem! Silly me I had entered the wrong data directory where the store is! Thanks – salvu Aug 03 '11 at 13:43