Kan*_*kar 6 cql cassandra nosql cql3
如果在CQL shell中使用此代码,我将获得该键空间中所有表的名称.
DESCRIBE TABLES;
Run Code Online (Sandbox Code Playgroud)
我想使用ResulSet检索相同的数据.下面是我在Java中的代码.
String query = "DESCRIBE TABLES;";
ResultSet rs = session.execute(query);
for(Row row : rs) {
System.out.println(row);
}
Run Code Online (Sandbox Code Playgroud)
会话和群集早先已初始化为:
Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
Session session = cluster.connect("keyspace_name");
Run Code Online (Sandbox Code Playgroud)
或者我想知道Java代码来检索密钥空间中的表名.
系统表的模式在版本之间有很大的不同.最好依赖于内置版本特定解析的驱动程序元数据.从Java驱动程序使用
Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
Collection<TableMetadata> tables = cluster.getMetadata()
.getKeyspace("keyspace_name")
.getTables(); // TableMetadata has name in getName(), along with lots of other info
// to convert to list of the names
List<String> tableNames = tables.stream()
.map(tm -> tm.getName())
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)