- You should have an Astra account
- You should Create and Astra Database
- You should Have an Astra Token
- You should Download your Secure bundle
- You should install Java Development Kit (JDK) 8: Use the reference documentation to install a Java Development Kit, Validate your installation with
java --version
- You should install Apache Maven: Use the reference documentation and validate your installation with
mvn -version
-
Please note that version 3.8+ is required to connect to Astra.
-
Update your
pom.xml
file with the latest version of the 3.x libraries:
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>${latest3x}</version>
</dependency>
🖥️. Sample Code (project astra-driver3x)
import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
public class AstraDriver3x {
// Define inputs
static final String ASTRA_ZIP_FILE = "<path_to_secureConnectBundle.zip>";
static final String ASTRA_USERNAME = "<provide_a_clientId>";
static final String ASTRA_PASSWORD = "<provide_a_clientSecret>";
static final String ASTRA_KEYSPACE = "<provide_your_keyspace>";
public static void main(String[] args) {
Logger logger = LoggerFactory.getLogger(AstraDriver3x.class);
try(Cluster cluster = Cluster.builder()
.withCloudSecureConnectBundle(new File(ASTRA_ZIP_FILE))
.withCredentials(ASTRA_USERNAME, ASTRA_PASSWORD)
.build() ) {
Session session = cluster.connect(ASTRA_KEYSPACE);
logger.info("[OK] Welcome to ASTRA. Connected to Keyspace {}", session.getLoggedKeyspace());
}
logger.info("[OK] Success");
System.exit(0);
}
}