jena tdb中的交易错误? [英] errors in transaction in jena tdb?

查看:216
本文介绍了jena tdb中的交易错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  String directory =EMAILADDRESS; 
//为tdb存储创建数据集
数据集ds = TDBFactory.createDataset(directory);
//创建默认的rdf模型
ds.begin(ReadWrite.WRITE);
模型模型= ds.getDefaultModel();
//写入tdb数据集

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

 模型模型= ds.getDefaultModel(); 
//写入tdb数据集
ds.begin(ReadWrite.WRITE);

然后它工作正常!但有时会出现这个错误:

  com.hp.hpl.jena.tdb.transaction。 TDBTransactionException:不在一个交易中

我知道第一种方法是正确的,但我不明白为什么没有响应查询。这是用于查询的代码:

  public class test4query extends Object {
public static String [] arr = new String [30];
public void mai(String s){
String directory =EMAILADDRESS;
数据集ds = TDBFactory.createDataset(directory);
ds.begin(ReadWrite.READ);
模型模型= 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 =嗨;
}
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)。


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

    }
}

解决方案

It is unclear when you get hat exception. The code example is full of parts that are commented out and does not use "m" at all.

You can not call ResultSetFormatter.out(rs) after you have called qExec.close or ds.commit.

这篇关于jena tdb中的交易错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆