Harish Chandra
Harish Chandra

Reputation: 11

CREATE KEYSPACE using Cassandra builder

Instead of hard cording schema, I am trying to build using Cassandra API. My schema is

"CREATE KEYSPACE IF NOT EXISTS"

Example, for creating table we are using

SchemaBuilder.createTable(tableName).ifNotExists();

Same way how to create 'KEYSPACE'?

I am using Cassandra 3.x version.

Please help me.

Upvotes: 1

Views: 503

Answers (2)

prostý člověk
prostý člověk

Reputation: 939

The com.datastax.oss.driver.api.querybuilder.SchemaBuilder API provides SchemaBuilder.createTable("<keyspace>", "<tableName>") in one shot.

Upvotes: 1

anshul_cached
anshul_cached

Reputation: 762

You can do

SchemaBuilder.createKeyspace(keyspaceName).ifNotExists() 

Cassandra-Java API DOC

Upvotes: 0

Related Questions