Query data using the Java binding and OQL
We show in this section how to query objects as defined in the ODL schema using the Java language binding and OQL.
static void query_students(org.eyedb.Database db) throws org.eyedb.Exception { org.eyedb.OQL oql = new org.eyedb.OQL(db, "select Student"); org.eyedb.ObjectArray obj_arr = new org.eyedb.ObjectArray(); oql.execute(obj_arr); int count = obj_arr.getCount(); for (int n = 0; n < count; n++) { Student s = (Student)obj_arr.getObject(n); if (s != null) { System.out.println(s.getFirstname() + " " + s.getLastname()); } } } static void query_courses(org.eyedb.Database db, String firstname, String lastname) throws org.eyedb.Exception { org.eyedb.OQL oql = new org.eyedb.OQL (db, "select c from Course c where " + "c.teacher.lastname = \"" + lastname + "\" && " + "c.teacher.firstname = \"" + firstname + "\""); org.eyedb.ObjectArray obj_arr = new org.eyedb.ObjectArray(); oql.execute(obj_arr); int count = obj_arr.getCount(); for (int n = 0; n < count; n++) { Course c = (Course)obj_arr.getObject(n); if (c != null) { System.out.println(firstname + " " + lastname + ": " + c.getTitle() + " " + c.getDescription()); } } }
View the whole Java file