【Sesame】实现MySQL底层存储对接

本文主要提供了一种方法,用于将sesame图数据库以MySQL形式存储于关系型数据库。

搭建MySQL服务器

这个跳过。记录下访问配置信息:
server: localhost
port: 3306
name: root
password: rootpassword
开启数据库连接,新建一个数据库叫rdf_test

编写Sesame顶层代码

public RepoUtil() {
         
          valueFactory = new ValueFactoryImpl();     //Initialize the value factory for URI and Literal
          MySqlStore ms = new MySqlStore();
          /* Set the parameters for mysql store */
          ms.setServerName("localhost");
          ms.setPortNumber(3306);
          ms.setDatabaseName("rdf_test");
          ms.setUser("root");
          ms.setPassword("rootpassword");
          /* Initialize the sail repository w*/
          repo = new SailRepository(ms);
          try {
               repo.initialize();     //or ms.initialize();
          } catch (RepositoryException e) {
               e.printStackTrace();
          }
         
          try {
               repoConn = repo.getConnection();     //get connection
               URI s = valueFactory.createURI("http://test.com/user/12345");
               URI p = valueFactory.createURI("http://test.com/actioin/create/3");
               Literal o = valueFactory.createLiteral("卧槽 看不懂!");
               repoConn.add(s, p, o);
               repoConn.close();                         //close the connection
          } catch (RepositoryException e) {
               e.printStackTrace();
          }
          try {
               repo.shutDown();      //It is important! otherwise it would not delete "locked" table.
          } catch (RepositoryException e) {
               e.printStackTrace();
          }/**/
     }

顶层调用本段代码,即可实现sesame对MySQL数据库的访问、存储及查询。
sesame已经封装好mysql对应的代码。
注意点:
数据库操作断开会留下lock表,此时比较复杂,需要处理roll back等操作。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值