Project

General

Profile

Actions

Developer's Guide Version v1.x

This page describes how to develop a Java program with OntoQL library. This guide is based on the Eclipse IDE.

We suppose that an OntoDB schema is correctly installed. If it is not the case, please refer to this page.

Create a new Java project

  • Start Eclipse
  • Create a new Java project (File => New => Java Project) and from the Project name field, input OntoQLSample value, and click on finish

Configure your Java project

  • From your operating system explorer, create a lib directory
  • Copy from the OntoQL distribution (lib) all the jar files into the new lib directory
  • From the properties of the OntoQLSample project, add the previous Jar into the classpath (Add JARs option)
  • Create a config directory and add it as a source forlders to your project.
  • Copy from the OntoQL distribution (config) the ontology_model.xml file into the new config directory

Create a main class

  • Create a new class called OntoQLSampleTest with a specific package (at your convenance).
  • Copy this code
public class OntoQLSampleTest {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        final String host = "localhost";
        final String login = "postgres";
        final String password = "psql";
        final String port = "5432";
        final String sid = "your_example_obdb";

        Class.forName("org.postgresql.Driver");

        Connection c = DriverManager.getConnection(getURL(host, port, sid), login, password);
        c.setAutoCommit(false);
        OntoQLSession s = new OntoQLSessionImpl(c);
        s.setReferenceLanguage(OntoQLHelper.FRENCH);

        OntoQLStatement statement = s.createOntoQLStatement();
        statement.executeUpdate("INSERT INTO #ontology (#namespace) values ('http://www.lias-lab.fr/')");
        s.setDefaultNameSpace("http://www.lias-lab.fr/");
        statement.executeUpdate("CREATE #CLASS myFirstClass (DESCRIPTOR (#code = 'myFirstClassCode'))");

        final OntoQLResultSet executeQuery = statement.executeQuery("select #code from #class where #code='myFirstClassCode'");
        executeQuery.next();
        System.out.println(executeQuery.getString(1));

        c.rollback();
        c.close();
    }

    private static String getURL(String ip, String port, String sid) {
        return "jdbc:postgresql://" + ip + ":" + port + "/" + sid;
    }
}
  • Execute your program

Updated by Mickael BARON almost 7 years ago · 17 revisions