Query the database

If you finally want to query your database, you can make usage of SQL or also within the Java API.

E.g. if you want to query a whole class

String sqlQuery = "select * from "+myclass;
List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(sqlQuery);

You can pass any string which is a defined OrientDB dialect SQL query.

If you want to do it within your code, the example below will give you the same results like with SQL.

String s_myClass = "Student";
ORecordIteratorClass<ODocument> i_myClass = database.browseClass(s_myClass);

if(i_myClass.hasNext())
{ 

     for(ODocument d: i_myClass)
     {
          System.out.println(d.toString());
     }

     ...
}

Further you can access the fields of the documents, e.g. for manipulation or so.

Now that we're are done with all needed functionality, we can build a small tool to automate all these operations and operate it via command shell or so.

For further information, all used classes in this chapter are listed below:

results matching ""

    No results matching ""