引入Gradle依赖
// https://mvnrepository.com/artifact/com.datastax.oss/java-driver-core
compile group: 'com.datastax.oss', name: 'java-driver-core', version: '4.8.0'
启动Cassandra
docker run -p 9042:9042 -d ttbb/cassandra:stand-alone-eth0
查询版本号
//注意,driver 4.0版本删除了cluster对象,session才是现在基础的对象
public class CassandraSession {
public static void main(String[] args) throws Exception {
try (CqlSession session = CqlSession.builder().build()) {
ResultSet rs = session.execute("select release_version from system.local");
Row row = rs.one();
System.out.println(row.getString("release_version"));
}
}
}
//输出 4.0-beta1
demo代码参考
https://github.com/Shoothzj/java-demo
网友评论