O'Reilly logo

Apache Cassandra Essentials by Nitin Padalia

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading and writing to the Cassandra cluster

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required