I am trying to write propreties into a model and then query it.This part of mycode:
String directory = "EMAILADDRESS" ;
//create the dataset for the tdb store
Dataset ds = TDBFactory.createDataset(directory) ;
//create default rdf model
ds.begin(ReadWrite.WRITE);
Model model = ds.getDefaultModel() ;
//write to the tdb dataset
When I write this and then query the query shows no result ...but when I interchange the order of model and begin i.e.
Model model = ds.getDefaultModel() ;
//write to the tdb dataset
ds.begin(ReadWrite.WRITE);
Then it works fine!! but it sometimes gives this error:
com.hp.hpl.jena.tdb.transaction.TDBTransactionException: Not in a transaction
I know that first way is correct but I don't understand why it doesn't respond to queries..This is code for quering:
public class test4query extends Object {
public static String[] arr=new String[30];
public void mai (String s) {
String directory = "EMAILADDRESS" ;
Dataset ds = TDBFactory.createDataset(directory) ;
ds.begin(ReadWrite.READ) ;
Model model = ds.getDefaultModel() ;
QueryExecution qExec = QueryExecutionFactory.create(s, ds) ;
int i=0;
try{
ResultSet rs = qExec.execSelect() ;
String x=rs.toString();
while (rs.hasNext()) {
QuerySolution qs = rs.next();
String rds;
if(qs.get("x")!=null) {
rds = qs.get("x").toString();
} else {
rds="hi";
}
if(rds==null) {
break;
}
System.out.println(rds);
arr[i] = rds;
i++;
}
} finally
{qExec.close() ;
ds.commit();
ds.end();
}
}
}