Heim >Datenbank >MySQL-Tutorial >【Sesame】导出已经存在的三元组数据
在Sesame系列上一篇介绍了如何添加三元组数据,本文将介绍如何导出三元组数据到文件。 1. 建立数据库连接 static NativeStore nativeStore;static Repository repo;static String rdfFile;static {rdfFile = exportTemp.ttl;repoFile = new File(ldbc);nativ
在Sesame系列上一篇介绍了如何添加三元组数据,本文将介绍如何导出三元组数据到文件。
static NativeStore nativeStore; static Repository repo; static String rdfFile; static { rdfFile = "exportTemp.ttl"; repoFile = new File("ldbc"); nativeStore = new NativeStore(repoFile); repo = new SailRepository(nativeStore); }
public static void databaseInitialize() { try { repo.initialize(); } catch (RepositoryException e) { e.printStackTrace(); } }
public static void outputDatabase(String filename) { try { FileOutputStream out = new FileOutputStream(filename); RDFWriter writer = Rio.createWriter(RDFFormat.TURTLE, out); RepositoryConnection newConn = repo.getConnection(); newConn.export(writer); } catch (RepositoryException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (RDFHandlerException e) { e.printStackTrace(); } System.out.println("-------Output ends--------"); }