Executing statements
While the Cluster
acts as a central place to manage connection-level configuration options, you will need to establish a Session
to perform actual work against the cluster. This is done by calling the connect()
method on your Cluster
instance.
To run the following examples, you will need to create the contacts
keyspace and contact
table, as follows:
CREATE KEYSPACE contacts WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }; USE contacts; CREATE TABLE contact ( id UUID, email TEXT PRIMARY KEY );
After the schema is created, you can 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...