tencent cloud

TDSQL Boundless

Connecting to the Database

PDF
Modo Foco
Tamanho da Fonte
Última atualização: 2026-02-10 10:54:56

Prerequisites

An instance in HBase-compatible mode has been created.
The related data tables and database users have been created.

Step 1: Add Client Dependencies

Add jar package dependencies to the pom.xml file of your local Java project.
<dependency>
<groupId>com.tencent.tdsql</groupId>
<artifactId>tdsql-hbase-shaded-client</artifactId>
<version>1.0.9</version>
</dependency>
Note:
Version update: It is recommended to use the latest version of the jar package, as older versions may not support the new server.
Version check: Refer to the published tdsql-hbase-shaded-client version in the central repository and replace the version number with the latest published version number.

Step 2: Configure Client Connection Parameters

public class HBaseInsertDemo {
public static void main(String[] args) throws Exception {
// Configure HBase
Configuration conf = HBaseConfiguration.create();
config.set("hbase.client.tdsql.quorum", "10.10.10.10:6752"); // HBase service RPC port
config.setBoolean("hbase.tdsql.hash.partition", Boolean.TRUE); // Enable HBase compatible mode
config.set("mysql.native.username", "test"); // Database username
config.set("mysql.native.password", "test123"); // Database password

Connection connection = ConnectionFactory.createConnection(conf);

// Get the Table handle
TableName tableName = TableName.valueOf("ht1");
Table table = connection.getTable(tableName);

// Prepare to insert data
Put put = new Put(Bytes.toBytes("rk801"));
put.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("column1"), Bytes.toBytes("v1")); // Column family, column qualifier, value
table.put(put);

// Disable resources.
table.close();
connection.close();

System.out.println("Data inserted successfully!");
}
}
Parameter description:
Parameter
Description
hbase.client.tdsql.quorum
HBase service RPC port.
hbase.tdsql.hash.partition
Must be set to TRUE to enable HBase compatible mode.
mysql.native.username
As with MySQL, you can set it via SQL statements for creating users, ignoring MySQL privileges.
mysql.native.password

Ajuda e Suporte

Esta página foi útil?

comentários