Cassandra driver 入门教程 (一) 连接数据库,获取版本号

1 建立Cluster对象

Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();

2 获得Session

Session session = cluster.connect();

3 执行查询

session.execute("select release_version from System.local");

4 遍历结果数据

Row row = rs.one();

这里只有一行,就用rs.one()吧;


整体代码:

public static void getVersion(){
		try(Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();){
			Session session = cluster.connect();
			ResultSet rs = session.execute("select release_version from System.local");
			Row row = rs.one();
			System.out.println("release_version: "+row.getString("release_version"));
		}
	}


你可能感兴趣的:(cassandra)