我正在尝试将属性写入模型,然后查询它。我的代码的这一部分:
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
当我写这个然后查询时,查询没有显示结果......但是当我交换模型的顺序并开始时,即
Model model = ds.getDefaultModel() ;
//write to the tdb dataset
ds.begin(ReadWrite.WRITE);
然后就可以正常工作了!!但有时会出现此错误:
com.hp.hpl.jena.tdb.transaction.TDBTransactionException: Not in a transaction
我知道第一种方法是正确的,但我不明白为什么它不响应查询。这是查询代码:
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();
}
}
}
目前尚不清楚您何时获得帽子例外。该代码示例充满了被注释掉的部分,并且根本没有使用“m”。
调用 qExec.close 或 ds.commit 后,无法调用 ResultSetFormatter.out(rs)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)