jena tdb中的事务错误?

时间:2014-06-22 07:25:57

标签: error-handling sparql jena tdb

我正在尝试将propreties写入模型然后查询它。这部分代码:

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

    }
}

1 个答案:

答案 0 :(得分:0)

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

调用qExec.close或ds.commit后,无法调用ResultSetFormatter.out(rs)。