Skip to content

Setting up SDB for MySQL




 

Jena is a semantic web framework implemented in Java. It allows you to store/query/inference RDF/RDSF/OWL triples. In Jena a set of triples (in RDF) are called Model or stored within Model object. By default Jena creates in-memory models, but this is not suitable if you have pretty large set of triples to process. Here comes SDB to rescue you. It’s a component of Jena that allows you to store these models in relational databases like MySQL, MSSQL, PostgreSQL, Oracle, etc; This post describes my experience while setting up SDB on Ubuntu.

  1. Download SDB. Extract it into some folder.
  2. SDB works with SUN Java only. Ubuntu has GNU Java installed by default. You need to install SUN Java and set it as default.
    [Note: you know why this point is important? I wasted 1 hr when I did same setup second time. Later I realized I was using GNU libgcj (gij/gcj). For god's sake, someone please kill gcj...
  3. Create a database for SDB in MySQL. I did using phpMyAdmin. Let’s call this database SDB2.
  4. Prepare a store description file. It serves as config for SDB and contains information like where to connect. You will find one such example file in the SDB directory. Here is an example for the description file I have used:
    @prefix sdb: <http://jena.hpl.hp.com/2007/sdb#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
    # MySQL - InnoDB
    <#store> rdf:type sdb:Store ;
    sdb:layout "layout2" ;
    sdb:connection <#conn> ;
    sdb:engine "InnoDB" ; # MySQL specific
    .
    <#conn> rdf:type sdb:SDBConnection ;
    sdb:sdbType "MySQL" ; # Needed for JDBC URL
    sdb:sdbHost "localhost" ; # or the IP address of the database server
    sdb:sdbName "SDB2" ; # MySQL database name
    sdb:sdbUser "username";
    sdb:sdbPassword "password";
    sdb:driver "com.mysql.jdbc.Driver" ;
    .
  5. Set environment variables:

    SDB installation directory –
    export SDBROOT="/home/ankit/tmp/SDB"

    Path to MySQL JDBC commector jar which contains com.mysql.jdbc.Driver class.
    export SDB_JDBC="/home/ankit/tmp/SDB/mysql-connector-java-5.1.7-bin.jar"

  6. Required tables must be created in database before we can use it. Run following to initialize SDB2 database. This creates 4 tables inside SDB2.
    bin/sdbconfig --sdb=sdb.ttl --create
    If this fails, somthing went wrong with settings. Check them again.
  7. Next you can run test suit to ensure everything is working fine.
    bin/sdbtest --sdb=sdb.ttl testing/manifest-sdb.ttl

    In my case one testcase failed stating -

    Failure: Unicode-5(com.hp.hpl.jena.sdb.test.junit.QueryTestSDB): Results sets not the same

I decided to write this as the SDB wiki does now contains clear steps to follow. Hope your semantic (web) application ROCKS !

- ankit

One Comment

  1. sriram

    hi,
    i am also facing the same problem. getting the same message u got. will that be a problem in connecting SDB and mysql? pls reply..

    Posted on 10-Sep-09 at 8:54 pm | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image