【问题标题】:errors in transaction in jena tdb?jena tdb 中的事务错误?
【发布时间】:2014-06-22 07:25:57
【问题描述】:

我正在尝试将属性写入模型,然后对其进行查询。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

当我写这个然后查询时,查询没有显示结果......但是当我交换模型的顺序并开始时,即

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

    }
}

【问题讨论】:

标签: error-handling sparql jena tdb


【解决方案1】:

目前还不清楚您何时获得帽子异常。代码示例充满了被注释掉的部分,根本不使用“m”。

在调用 qExec.close 或 ds.commit 后,您不能再调用 ResultSetFormatter.out(rs)。

【讨论】:

  • 代码示例不完整。它不会显示您写入Dataset,提交这些写入,然后尝试稍后读取它。请用数据构建一个最小的工作示例,以演示我们可以自己运行的错误。如果我们无法复制错误,那么您获得解决方案的可能性就会大大降低。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多