import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import oracle.kv.KVStore; import oracle.kv.KVStoreConfig; import oracle.kv.KVStoreFactory; import oracle.kv.table.Row; import oracle.kv.table.Table; import oracle.kv.table.TableAPI; public class TableReadWrite { // KV Store public static KVStore kvstore = null; public static void main(String[] args) throws ParseException { TableReadWrite tableReadWrite = new TableReadWrite(); // get the host to connect as first parameter String host = "localhost:5000"; // get the store Name String store = "kvstore"; KVStoreConfig kvconfig = new KVStoreConfig(store, host); // Connect to the store kvstore = KVStoreFactory.getStore(kvconfig); // get the Table API TableAPI tableAPI = kvstore.getTableAPI(); //get a reference to the table Table empTable = tableAPI.getTable("emp"); // Get a Row instance Row empRow = empTable.createRow(); // put data in the row empRow.put("empno", 10); empRow.put("ename", "Gunther"); empRow.put("job", "Developer"); empRow.put("mgr", 0); // date handling SimpleDateFormat formatter = new SimpleDateFormat("dd.mm.yyyy"); Date date = (Date) formatter.parse("01.04.2014"); empRow.put("hiredate", date.getTime()); empRow.put("sal", 1000f); empRow.put("comm", 5f); empRow.put("deptno", 10); // write the data to the store tableAPI.put(empRow, null, null); //-------- Read the data again from the Store //------- Use an Index //get Ref on the index Index empEmpnoIndex = empTable.getIndex("IDX_EMP_ENAME"); IndexKey empEmpnoIndexKey=empEmpnoIndex.createIndexKey(); TableIterator result = tableAPI.tableIterator(empEmpnoIndexKey, null, null); while (result.hasNext()) { Row empRowResult = result.next(); // read row String jRow=empRowResult.toJsonString(true); System.out.println(jRow); } } }