Executing statements

While the Cluster acts as a central place to manage connection-level configuration options, you will need to establish a Session instance to perform actual work against the cluster. This is done by calling the connect() method on your Cluster instance. Here, we connect to the contacts keyspace:

private Session session; // defined at class level
session = cluster.connect("contacts");

Once you have created the Session, you will be able to execute CQL statements as follows:

String insert = "INSERT INTO contact (id, email) " +
  "VALUES (" +
  "bd297650-2885-11e4-8c21-0800200c9a66," +
  "'contact@example.com' " +
");";
session.execute(insert);

You can submit any valid CQL statement to the execute() method, including schema modifications. ...

Get Cassandra High Availability now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.