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";


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

        OntoQLStatement statement = s.createOntoQLStatement();
        statement.executeUpdate("INSERT INTO #ontology (#namespace) values ('')");
        statement.executeUpdate("CREATE #CLASS myFirstClass (DESCRIPTOR (#code = 'myFirstClassCode'))");

        final OntoQLResultSet executeQuery = statement.executeQuery("select #code from #class where #code='myFirstClassCode'");;


    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