Difficulty: Beginner
Estimated Time: 5 - 10 minutes

The Datastax Java Driver for Apache Cassandra™ is a modern, feature-rich and highly tunable Java client library for Apache Cassandra® (2.1+) and DataStax Enterprise (4.7+), and DataStax Astra, using exclusively Cassandra’s binary protocol and Cassandra Query Language (CQL) v3.

In this scenario, you will:

  • Connect to an Apache Cassandra™ instance with the DataStax Java driver
  • Use the driver to execute CQL statements against Apache Cassandra™ that do the following:
    • Create the a keyspace and table programmatically
    • Insert a user into a table
    • Select that user back out
    • Update the user's email
    • Delete the user from the table
  • Process CQL query results programmatically

This scenario is also available on our datastax.com/dev site, where you can find many more resources to help you succeed with Apache Cassandra™.

Congratulations! You now have the basic knowledge of using the Java driver for Apache Cassandra™.

Get your hands on the DataStax Drivers at DataStax Downloads

For more learning, try the Cassandra Fundamentals learning series on datastax.com/dev.

Was this helpful? Please give this scenario a rating (click on the stars above).

Have questions or more feedback? Send us a message.

Want a free 5 GB Cassandra database in the cloud to continue experimenting? Sign up and launch your database with a few clicks at astra.datastax.com!

Try It Out: DataStax Java Driver for Apache Cassandra™

Step 1 of 6

Java project Setup

Interact with Cassandra in the Java programming language using The DataStax Java Driver! This short scenario walks through using CRUD operations against a Cassandra instance in Java.

Wait until Cassandra has finished starting up. Enter the quickstart-java directory. The Maven build automation tool manages our dependencies.

cd ~/quickstart-java

The pom.xml file declares the dependencies , including the latest version of Java driver.


Review the dependencies with cat pom.xml if you wish, otherwise continue with connecting to Cassandra.

To make things easy, we will be using jshell. The Java Shell tool (JShell) is an interactive tool for learning the Java programming language and prototyping Java code. Start jshell from the project directory.

mvn jshell:run

Once jshell is running, you are going to need to import the CqlSession class to connect to the cluster, as well as the cql package:

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.cql.*;

Now that Apache Cassandra is running, let's configure our connection to the instance.