Use o driver Cassandra CQL Java para conectar-se ao LindormTable e executar operações DDL e DML.
Pré-requisitos
Java Development Kit (JDK) 1.8 ou superior instalado.
Driver Cassandra CQL Java instale. Instalar o driver Cassandra CQL.
Endereço IP do cliente adicionado à lista de permissões da instância Lindorm. Configurar uma lista de permissões.
-
[KV化][2026-02-10] 原界面词"CQL连接"(uicontrol)替换为美杜莎conref引用
Endpoint de CQL Connection obtido. No console do Lindorm, acesse os detalhes da instância > Endpoints > aba LindormTable > Cassandra-compatible address para obter o endereço privado ou público (nome de usuário e senha padrão:
root). Visualize endpoints.
Procedimento
-
Configure os parâmetros de conexão.
String[] contactPoints = new String[]{ "<host>" }; ClusterNota-
[KV化][2026-02-10] 原界面词"CQL连接"(uicontrol)替换为美杜莎conref引用
host: Endereço de CQL Connection no console do Lindorm. Exemplo:
ld-bp17j28j2y7pm****-proxy-lindorm.lindorm.rds.aliyuncs.com. username: Nome da conta da instância Lindorm. Padrão: root.
-
[KV化][2026-02-10] 原界面词"集群管理系统"(uicontrol)替换为美杜莎conref引用
password: Senha da conta da instância Lindorm. Se esquecida, redefina-a no Cluster Management System do LindormTable. Alterar senha do usuário.
-
-
Acesse as wide tables do Lindorm pela API Cassandra CQL Java.
-
Operações DDL
// Create a keyspace and specify its strategy and replication factor. session.execute( "CREATE KEYSPACE IF NOT EXISTS testKeyspace WITH replication " + "= {'class':'SimpleStrategy', 'replication_factor':1};"); // Create a table and specify its primary key, cluster key, and regular key. session.execute( "CREATE TABLE IF NOT EXISTS testKeyspace.testTable (" + "id int PRIMARY KEY," + "name text," + "age int," + "address text" + ");"); // Truncate the table. session.execute("TRUNCATE TABLE testKeyspace.testTable;"); // Drop the table. session.execute("DROP TABLE testKeyspace.testTable "); -
Operações DML
// Perform an insert operation. session.execute( "INSERT INTO testKeyspace.testTable (id, name, age, address) " + "VALUES (" + "1," + "'testname'," + "11," + "'hangzhou');"); // Perform a select operation. `select *` retrieves all columns. To retrieve data from specific columns, specify their names. ResultSet res = session.execute( "SELECT * FROM testKeyspace.testTable ;"); // To retrieve data from each column: for (Row row : res) { int id = row.getInt("id"); String name = row.getString("name"); int age = row.getInt("age"); String address = row.getString("address"); } // Close the session. session.close(); // Close the cluster. cluster.close();
-