You can execute the SHOW TABLES statement to list the names of tables in the current database.
For more information about the SHOW TABLES statement, see List mapping table names.
Prerequisites
An OTSClient instance is initialized. For more information, see Initialize an OTSClient instance.
A mapping table is created. For more information, see Create mapping tables for tables.
Usage notes
Tablestore SDK for Java V5.13.0 or later supports the SQL query feature. Before you use the SQL query feature, make sure that Tablestore SDK for Java V5.13.0 or later is obtained. For more information about the version history of Tablestore SDK for Java, see Version history of Tablestore SDK for Java.
Parameters
Parameter | Description |
query | The SQL statement. Configure the parameter based on the required feature. |
Example
The following sample code provides an example on how to execute the SHOW TABLES
statement to list the names of mapping tables.
private static void showTable(SyncClient client) {
// Create an SQL request.
SQLQueryRequest request = new SQLQueryRequest("show tables");
// Obtain the response to the SQL request.
SQLQueryResponse response = client.sqlQuery(request);
// Obtain the schema of the returned results of the SQL request.
SQLTableMeta tableMeta = response.getSQLResultSet().getSQLTableMeta();
System.out.println("response table schema: " + tableMeta.getSchema());
// Use SQL ResultSet to obtain all returned results of the SQL query statement.
System.out.println("response resultset:");
SQLResultSet resultSet = response.getSQLResultSet();
while (resultSet.hasNext()) {
SQLRow row = resultSet.next();
System.out.println(row.getString(0));
}
// Use the SQLUtils function to parse the response to obtain the list of table names.
System.out.println("response sqlutils resultset:");
List<String> tables = SQLUtils.parseShowTablesResponse(response);
for (String table : tables) {
System.out.print(table + ", ");
}
}
Sample response:
response table schema: [Tables_in_$instanceName:STRING]
response resultset:
test_table
response sqlutils resultset:
test_table,
References
After you query the names of the mapping tables, perform operations based on your business requirements.
To use a mapping table to query data that meets specific conditions, execute the
SELECT
statement. For more information, see Query data.To query details of a specific mapping table such as field names and field types, execute the
DESCRIBE
statement. For more information, see Query information about tables.To update the attribute column of the mapping table after the attribute column of the data table is changed, execute the
ALTER TABLE
statement. For more information, see Update attribute columns of mapping tables.To delete a mapping table, execute the
DROP MAPPING TABLE
statement. For more information, see Delete mapping tables.