Код: Выделить всё
import com.toshiba.mwcloud.gs.*;
import java.util.*;
public class GridDBExample {
public static void main(String[] args) {
try {
// Establish connection to GridDB
GridStore store = GridStoreFactory.getInstance().getStore(
"notificationAddress=239.0.0.1;notificationPort=31999;clusterName=defaultCluster;user=admin;password=admin;"
);
// Define container schema and create container
ContainerInfo containerInfo = new ContainerInfo(
"sample_container",
ContainerType.COLLECTION,
new String[]{"id", "value"},
new Type[]{Type.INTEGER, Type.STRING}
);
Collection con = store.putContainer(containerInfo);
// Insert sample data
for (int i = 0; i < 10; i++) {
con.put(new Object[]{i, "value" + i});
}
// Parameterized query: expecting to retrieve rows where id >= 5
Query query = con.query("SELECT * WHERE id >= ?");
query.bind(5);
RowSet rs = query.fetch();
// Iterate and print results
while (rs.hasNext()) {
Row row = rs.next();
System.out.println("id: " + row.getInteger(0) + ", value: " + row.getString(1));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... result-set