You can execute CQL queries using the execute() method of Session class. Therefore, create the session object as shown below. Session session = nnect(“ Your keyspace name ” ) If you already have a keyspace, you can set it to the existing one by passing the keyspace name in string format to this method as shown below. This method creates a new session and initializes it. You can build a cluster object using a single line of code as shown below.Ĭluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build() Ĭreate an instance of Session object using the connect() method of Cluster class as shown below. The following code shows how to create a cluster object. To do so, you have a method called build() in the Cluster.Builder class. Using the new builder object, create a cluster object. Adding contact point to the Cluster.Builder objectĬluster.Builder builder2 = build.addContactPoint( "127.0.0.1" ) Step1: Create a Cluster Objectįirst of all, create an instance of the Cluster.builder class of package as shown below.Ĭluster.Builder builder1 = Cluster.builder() Īdd a contact point (IP address of the node) using the addContactPoint() method of Cluster.Builder object. Follow the steps given below to create a table using Java API. You can create a table using the execute() method of Session class. Since we have deleted the keyspace tutorialspoint, you will not find it in the keyspaces list. Here you can observe the table created with the given columns. Verify the table using the select statement as shown below.Įmp_id | emp_city | emp_name | emp_phone | emp_sal The select statement will give you the schema. It will have details such as employee name, id, city, salary, and phone number. Given below is an example to create a table in Cassandra using cqlsh. You can define a primary key of a table as shown below. A primary key is made of one or more columns of a table. Therefore,defining a primary key is mandatory while creating a table. The primary key is a column that is used to uniquely identify a row. Given below is the syntax for creating a table. You can create a table using the command CREATE TABLE.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |