Migrating the DataStax Java driver to connect with Apollo databases

Migrate your existing DataStax Java driver to a version compatible with Cassandra databases.

Complete the following procedure to migrate your existing DataStax Java driver to a version capable of connecting to Apollo databases created using DataStax Apollo on Constellation.

Prerequisites

  1. Create a DataStax Apollo database.
  2. Download the secure connect bundle to obtain connection credentials for your DataStax Apollo database.

Procedure

  1. In your existing DSE Java driver code, update dependencies to include the DSE Java driver version that can connect to Apollo databases.
    • DataStax Java driver for Apache Cassandra 4.x

      <dependency>
        <groupId>com.datastax.oss</groupId>
        <artifactId>java-driver-core</artifactId>
        <version>4.3.0</version>
      </dependency>
      
    • DataStax Java driver for Apache Cassandra 3.x

      <dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>cassandra-driver-core</artifactId>
        <version>3.8.0</version>
      </dependency>
      
    • DSE Java 2.x

      <dependency>
        <groupId>com.datastax.dse</groupId>
        <artifactId>dse-java-driver-core</artifactId>
        <version>2.3.0</version>
      </dependency>
      
    • DSE Java 1.x

      <dependency>
        <groupId>com.datastax.dse</groupId>
        <artifactId>dse-java-driver-core</artifactId>
        <version>1.9.0</version>
      </dependency>
      
  2. Modify the connection code to use the DataStax Apollo on Constellation API.

    In the CqlSession or Session objects (DseCluster or DseSession objects for DSE), include the path to the secure connect bundle for your Cassandra database (secure-connect-database_name.zip) in the withCloudSecureConnectBundle() method, as shown in the following example.

    • DataStax Java driver for Apache Cassandra 4.x

      CqlSession session = CqlSession.builder()
        .withCloudSecureConnectBundle("/path/to/secure-connect-database_name.zip")
        .withAuthCredentials("username","password")
        .withKeyspace("keyspace_name")
        .build())
      
    • DataStax Java driver for Apache Cassandra 3.x

      Session session = Cluster.builder()
        .withCloudSecureConnectBundle("/path/to/secure-connect-database_name.zip")
        .withAuthProvider(new PlainTextAuthProvider("username", "password"))
        .build()
        .connect("keyspace_name"))
      
    • Java 2.x

      DseSession session = DseSession.builder()
        .withCloudSecureConnectBundle("/path/to/secure-connect-database_name.zip")
        .withAuthCredentials("username", "password")
        .withKeyspace("keyspace_name")
        .build();
    • Java 1.x

      DseCluster cluster = DseCluster.builder()
        .withCloudSecureConnectBundle("/path/to/secure-connect-database_name.zip")
        .withCredentials("username", "password")
        .build();
      DseSession session = cluster.connect("keyspace_name");
      
  3. Build the project to test the connection.
    mvn clean compile exec:java -Dexec.mainClass=YourJavaDriver.java

    If successful, the code builds, compiles, and connects to your Cassandra database.