This version: 0.1
Date: 14 July 2003

HowTo Use Oracle Database System with Jena2

What is Oracle

Oracle is one of the leading, commercially-available SQL relational database management systems. It is available in a variety of configurations from small personal versions to fault-tolerant, enterprise-class versions. It runs on a variety of hardware/operating system platforms.  See http://www.oracle.com for more information. Jena2 has been tested with the Oracle 9i binary release, version 9.2.0.1.0.

Download and Installation of Oracle

As Oracle is commercially-available software, we cannot provide generic download instructions. We assume that Jena users wishing to use Oracle have access to an existing Oracle installation or access to the software. Below we list some assumptions and post-installation instructions for using Oracle with Jena. Currently, Jena2 has been tested with Oracle on Windows XP and on Linux AS.

Windows Platforms

Jena2 has been tested with Oracle on WindowsXP with the following versions.

Server:  Oracle 9.2.0.1.0       JDBC Thick Driver:  oci8, oci

Linux Platforms

Jena2 has been tested with Oracle on Linux AS with the following versions.

Server:  Oracle 9.2.0.1.0       JDBC Thick Driver:  oci (using the 9.2.0.3 versions of ojdbc14.jar and ocrs12.zip)

A user account and password are required to access the Oracle server. Typically, Oracle is installed with a demo database and user account that may be used for testing and experimentation. In the examples below, we assume the use of this default account (user name is scott and password is tiger). If you have your own Oracle user name and password, please use those values for DB_USER, DB_PASSWD.  The DB_URL value should be set as indicated below.

jdbc:oracle:oci:@       Uses the thick JDBC client and connects to the default local database.
jdbc:oracle:oci:@<tnsname>      Uses the thick JDBC client and connects to the specified database.
jdbc:oracle:thin:@       Uses the thin JDBC client and connects to the default local database (untested with Jena2).
jdbc:oracle:thin:@<host>:port:<sid>       Uses the thin  JDBC client and connects to a database with the specified sid on the specified host on the specified port (untested with Jena2).

In order to run Jena2 programs with Oracle, make sure that your CLASSPATH includes the jar files for classes12.jar and nls_charset12.jar.

Connecting Your Jena Program to Oracle

Jena supports both memory models and database models. In general, a Jena program may use both types of models identically. However, there are some differences in how the models are created. Creating a memory model can be done with a single Jena call. Creating a database model, or opening a previously created one, requires several steps as as follows.

  1. Important:
    Edit the source file com.hp.hpl.jena.db.impl.Driver_Oracle.java.
    Uncomment the Oracle import commands at the top of the file:
      import oracle.jdbc.OracleResultSet;
      import oracle.sql.BLOB;
    Comment-out the stubbed-out interfaces named BLOB and OracleResultSet.
  2. Load the JDBC driver. This enables the Jena program to communicate with the database instance.
  3. Create a database connection. This creates a Java object for a database connection.
  4. Create or open a model on the connection. This connects to the database and creates an empty model or opens a previously created model.

Steps 2-4 are illustrated in the following Java code.

// Load the Driver
String className = "oracle.jdbc.driver.DriverOracle"      // path of driver class
Class.forName (className);                      // load driver
String DB_URL = "jdbc:oracle:oci:@";       // URL of database server
String DB_USER = "scott";                        // database user id
String DB_PASSWD = "tiger";                          // database password
String DB = "Oracle";                            // database type
 
// Create database connection
IDBConnection conn = new DBConnection ( URL, DB_USER, DB_PASSWD, DB );
// Create a model in the database
ModelMaker maker = ModelFactory.createModelRDBMaker(conn);
ModelRDB m = maker.createModel ();
 
< your Jena code to work with the model goes here >
 
// Remove the model. NOTE: this deletes the model from the database.
// Subsequent attempts to open this model will fail.
m.remove();   // NOTE: remove deletes the model from the database
 
// Close the database connection                                                                                conn.close();                                                                                               
 
// Alternative to creating an unnamed model ...
// Create a named model
ModelRDB m = maker.createModel("myName");
 
...  later, or in another Jena application ...
 
// Open a named model.
ModelRDB m = maker.openModel("myName");

 

Usage Notes

Jena stores all models in a single database using whatever database (name) specified on the database connection. See the Jena Database Release Notes for details on the physical layout.

Known Bugs

We encountered problems with BLOBs when using the Oracle thin driver to access an Oracle database running on the Linux operating system, so we recommend use of the oci driver when using Linux.

Oracle Utility Commands

Some Jena users may wish to occasionally access the Oracle database directly to determine if changes have taken effect. Some useful Oracle commands are listed here (replace the names in italics by names for your database instance). To use them, start the Oracle command line interface: SQLPlus username/password

List Tables: select * from TAB;

List Sequences: select * from SEQ;

Count All Rows in a Table: select count(*) from tableName;

List All Rows in a Table: select * from tableName;

Execute a SQLPlus command file: @<filename>    where <filename> is the path of a file containing SQLPlus commands

Exit SQLPlus: quit;