Todos os produtos
Search
Central de documentação

Tablestore:Consulta de dados por execução de instruções SQL

Última atualização: Jul 03, 2026

Este tópico descreve como usar o Tablestore SDK for Java para consultar dados em uma tabela executando instruções SQL.

Observações de uso

O recurso de consulta SQL é compatível com o Tablestore SDK for Java V5.13.0 e versões posteriores. Ao usar esse recurso, verifique se uma versão compatível do Tablestore SDK for Java está instalada.

Pré-requisitos

Método

public SQLQueryResponse sqlQuery(SQLQueryRequest request) throws TableStoreException, ClientException

Parâmetros do SQLQueryRequest

query String (obrigatório): instrução SQL a ser executada.

Código de exemplo

O código de exemplo a seguir demonstra como executar a instrução SELECT para consultar dados na tabela test_table e retornar no máximo 10 linhas.

Antes de executar o código, substitua o nome da tabela e os nomes dos campos pelas informações reais.
public static void queryDataExample(SyncClient client) {
    // Specify the SQL statement.
    SQLQueryRequest request = new SQLQueryRequest("select order_id, user_id, sku_id, price, num, total_price, order_status, create_time, modified_time from test_table limit 10;");
    SQLQueryResponse response = client.sqlQuery(request);

    // Specify the RequestId information.
    System.out.println("RequestId: " + response.getRequestId());
        /*// Read throughput consumption information.
        System.out.println("Read throughput consumption (by table):");
        for(Map.Entry<String, ConsumedCapacity> entry : response.getConsumedCapacity().entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue().getCapacityUnit().getReadCapacityUnit() + "CU");
        }*/

    // Obtain the SQL query results.
    SQLResultSet resultSet = response.getSQLResultSet();
    // Return the schema information.
    System.out.println("Schema: " + response.getSQLResultSet().getSQLTableMeta().getSchema());
    // Data details
    System.out.println("Data details:");
    while (resultSet.hasNext()) {
        SQLRow row = resultSet.next();
        System.out.println(row.get("order_id") + ", "
                + row.get("user_id") + ", "
                + row.get("sku_id") + ", "
                + row.get("price") + ", "
                + row.get("num") + ", "
                + row.get("total_price") + ", "
                + row.get("order_status") + ", "
                + row.get("create_time") + ", "
                + row.get("modified_time"));
    }
}

Perguntas frequentes

Referências