Dark Mode

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 database.

  • 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.

  • 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.
  • Initialize the DataStax Java driver.
  • Create a ConnectDatabase.java file in the /src/main/java directory for your Java project.
  • 1
  • Copy the following code for your DataStax driver into the ConnectDatabase.java 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.
  • 1
  • Make the following changes:
  • Save and close the ConnectDatabase.java 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.

  • 1