学习 Cassandra(六):Java Driver

依赖

编辑 pom.xml 文件,添加包依赖:

<dependency>  
    <groupId>com.datastax.cassandra</groupId>
    <artifactId>cassandra-driver-core</artifactId>
    <version>3.3.2</version>
</dependency>  

查看集群版本

Cluster cluster = Cluster.builder()  
        .addContactPoint("cassnadra_1")
        .addContactPoint("cassnadra_2")
        .addContactPoint("cassnadra_3")
        .withCredentials("用户名", "密码")
        .build();

Session session = cluster.connect();  
ResultSet rs = session.execute("select release_version from system.local");  
Row row = rs.one();  
System.out.println(row.getString("release_version"));

cluster.close();  

参考

Datastax - Java Driver for Apache Cassandra - Manual