DataStax Java driver

Use the unified DataStax Java driver to connect to your DataStax Astra DB database and begin building your own application.

You add a repository and dependencies to the pom.xml file for your project to download the appropriate .jar files for the Java driver and make them available to your code. Additionally, you implement a ConnectDatabase class to initialize the DSE Java driver.

DataStax recommends using the unified DataStax Java driver. If you have an existing Apache Cassandra or DataStax Enterprise (DSE) Java driver, migrate the driver to a version that is capable of connecting to Astra DB databases.


Alternatively, have a teammate provide access to their Astra DB database.


  1. Navigate to the pom.xml file at the root of your Java project and open it for editing.

For a complete pom.xml file, see the example pom.xml file below.

  1. Add the DataStax Java driver dependency to your pom.xml file, ensuring that the name of the dependency corresponds to the installed version: This dependency causes Maven to automatically download the appropriate .jar files found at the url specified in the repository for the DSE Java driver and make them available to your code.

  1. Save and close your pom.xml file.

  2. Initialize the DataStax Java driver.

  3. Create a file in the /src/main/java directory for your Java project.

cd **javaProject**/src/main/java
  1. Copy the following code for your DataStax driver into the file. The following example implements a ConnectDatabase class to connect to your Astra DB database, runs a CQL query, and prints the output to the console.

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.core.cql.Row;
import java.nio.file.Paths;

public class ConnectDatabase {

   public static void main(String[] args) {
       // Create the CqlSession object:
       try (CqlSession session = CqlSession.builder()
           .build()) {
           // Select the release_version from the system.local table:
           ResultSet rs = session.execute("select release_version from system.local");
           Row row =;
           //Print the results of the CQL query to the console:
           if (row != null) {
           } else {
               System.out.println("An error occurred.");
  1. Make the following changes:

    • Use the withCloudSecureConnectBundle() method to specify the path to the secure connect bundle for your Astra DB database.

    • Use the withAuthCredentials() method to specify the username and password for your database.

    • Use the withKeyspace() method to specify the keyspace name for your database.

  1. Save and close the file.

Example pom.xml file

You can use the following pom.xml file in your Java project to connect to your Astra DB database. If you already have a pom.xml file for your Java project, copy only the repository and dependencies as indicated in the previous steps.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
        <!-- START-javaDriverDependencyCore -->
        <!-- END-javaDriverDependencyCore -->
        <!-- START-javaDriverDependencyQuery -->
        <!-- END-javaDriverDependencyQuery -->
        <!-- START-javaDriverDependencyMapper -->
        <!-- END-javaDriverDependencyMapper -->