Running a simple query

Before running a query, perform store access as usual by obtaining a KVStore handle using the KVStoreFactory.getStore() method and a KVStoreConfig object.

To create the query, use KVStore.executeSync() This returns a StatementResult instance, which represents the result of an execution of a statement. There are two types of results, results of DDL statements and results of DML statements. DDL statements modify the database schema. CREATE TABLE, ALTER TABLE, and DROP TABLE are examples of DDL statements. DDL statements do not return data records, so iterator() and next() will return as if there was an empty result.

DML statements are non-updating queries. SQL SELECT-FROM-WHERE(SFW) statements are an example of a DML statement. DML statements may contain a set of records. Objects of StatementResult are not intended to be used across several threads.

For example, to run a simple query:

// Setup Store
String[] hhosts = {"", ""};
KVStoreConfig kconfig = new KVStoreConfig("exampleStore", hhosts);
KVStore store = KVStoreFactory.getStore(kconfig);

// Compile and Execute the SELECT statement
StatementResult result = store.executeSync("SELECT firstName,
age FROM Users");

// Get the results
for( RecordValue record : result ) {
     System.out.println("nameFirst: " +
     System.out.println("age: " +

where the query SELECTS the firstname and age from the table Users. Then, the results are displayed.