Hello, DataStax Community!

We want to make you aware of a few operational updates which will be carried out on the site. We are working hard to streamline the login process to integrate with other DataStax resources. As such, you will soon be prompted to update your password. Please note that your username will remain the same.

As we work to improve your user experience, please be aware that login to the DataStax Community will be unavailable for a few hours on:

  • Wednesday, July 15 16:00 PDT | 19:00 EDT | 20:00 BRT
  • Thursday, July 16 00:00 BST | 01:00 CEST | 04:30 IST | 07:00 CST | 09:00 AEST

For more info, check out the FAQ page. Thank you for being a valued member of our community.


mukheja.nitin avatar image
mukheja.nitin asked ·

How does an application connect to Cassandra using the driver?

I have seen example of cassandra driver where cluster name or keyspace name is specified without specifying the host ip address.

If i have multi node cluster how does the connection string work in cassandra.

10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

In its simplest form, you configure the driver with the "contact points" which are the list of nodes it can contact to discover the topology of the cluster. These contact points are similar to the way the seeds list work for the gossip protocol.

There are several drivers that DataStax maintain:

  • Java driver
  • Python driver
  • Node.js driver
  • C++ driver
  • C# driver

Note that this isn't the complete list of drivers for Cassandra. There are drivers maintained by other Cassandra enthusiasts in the community.

Let's use the Java driver as an example since it is the most popular. Here is a simple bit of code that creates a session to the cluster:

CqlSession session = CqlSession.builder()
   .addContactPoint(new InetSocketAddress("", 9042))

Note the method .addContactPoint() which identifies one of the nodes in the cluster as a contact point. Now that we've created a session object, we can execute queries against the database without needing to specify the contact points again. For example, we can insert data into a table with:

    SimpleStatement.builder( "INSERT INTO communityks.users (name, address) VALUES (?,?,?)")
        .addPositionalValues("tom", "100 Main Rd")

If you're interested, we have a Katacoda scenario for the Java Driver where you can quickly learn the basics of writing a Java app that writes to and reads from a Cassandra database. Try it out for yourself now. It only takes about 10 minutes.

Once you complete the scenario, it would be great if you complete the questionnaire at the end to provide us feedback as we would love to hear from you. Cheers!

2 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thank you eric for detailed explanation...

0 Likes 0 · ·

No worries. Cheers!

0 Likes 0 · ·