November 2015
Beginner to intermediate
172 pages
3h 47m
English
We're able to connect to our Cassandra server. Now let's write some data to it and read it back. The Session class provides a method called execute(), which is used to send read/write queries to Cassandra and get the result set back.
We can use CQL statements in the execute statement as strings. In the following example, we create a function that will create keyspace and a table for us. We're using CQL statements for creating keyspace and tables as string arguments to the execute method. Fetch the
Session object by using the getSession() method created earlier, as follows:
public static void createSchema() { // create keyspace getSession().execute( "CREATE KEYSPACE IF NOT EXISTS apachecassandra " + "WITH ...