errors in transaction in jena tdb?

与世无争的帅哥 提交于 2019-12-20 06:16:44

问题


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

    }
}

回答1:


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.



来源:https://stackoverflow.com/questions/24349035/errors-in-transaction-in-jena-tdb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!