Index

Table of contents

Cassandra

Command line

starting cassandra
sh bin/cassandra
open CQL command prompt
sh bin/cqlsh
help in CQL prompt
help
help on a specific topic
help BOOLEAN

Cassandra CQL

list databases
SELECT cluster_name, listen_address FROM system.local;
Get Cassandra version
select release_version from system.local;
Create keyspace (schema)
CREATE KEYSPACE [name] WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};
Use the named keyspace (schema) for all further queries
USE [name];
Drop Keyspace (schema)
DROP KEYSPACE IF EXISTS Test;
Create table
CREATE TABLE [name] (id bigint, PRIMARY KEY (id));
Insert record
INSERT INTO [name] (id) VALUES (1);
Select statment
SELECT * FROM [name];

Java driver

hello world
Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
Session session = cluster.connect();
ResultSet rs = session.execute("select release_version from system.local");
Row row = rs.one();
System.out.println(row.getString("release_version"));