这就是我写的:
public static void main(String[] args) {
Dataset dataset = TDBFactory.createDataset("/tmp/someThings");
dataset.begin(ReadWrite.WRITE);
Model model = dataset.getDefaultModel();
model.setNsPrefix("kg", "http://sankuai.com/kg");
Resource resource = model.createResource("http://sankuai.com/kg/jena");
resource.addProperty(model.createProperty("kg", "language"), "SPARQL");
dataset.commit();
System.out.println(model);
}
但是给我一些输出,它显示错误:
Exception in thread "main" org.apache.jena.tdb.transaction.TDBTransactionException: Not in a transaction
我做的事情有错吗?
答案 0 :(得分:2)
问题在于我检索模型时:
System.out.println(model);
它必须包含在交易中,我不是......