pom.xml file of your local Java project.<dependency><groupId>com.tencent.tdsql</groupId><artifactId>tdsql-hbase-shaded-client</artifactId><version>1.0.10</version></dependency>
// Javapublic class HBaseInsertDemo {public static void main(String[] args) throws Exception {// Configure HBaseConfiguration conf = HBaseConfiguration.create();conf.set("hbase.client.tdsql.quorum", "10.10.10.10:6752"); // RPC port for the HBase serviceconf.setBoolean("hbase.client.tdsql.enabled", Boolean.TRUE); // Enable HBase-compatible modeconf.set("mysql.native.username", "test"); // Database usernameconf.set("mysql.native.password", "test123"); // Database passwordConnection connection = ConnectionFactory.createConnection(conf);// Get the Table handleTableName tableName = TableName.valueOf("ht1");Table table = connection.getTable(tableName);// Prepare to insert dataPut put = new Put(Bytes.toBytes("rk801"));put.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("column1"), Bytes.toBytes("v1")); // Column family, column qualifier, valuetable.put(put);// Disable resources.table.close();connection.close();System.out.println("Data inserted successfully!");}}
Parameter | Description |
hbase.client.tdsql.quorum | HBase service RPC port. |
hbase.client.tdsql.enabled | Must be set to TRUE to enable HBase compatibility mode. |
mysql.native.username | As with MySQL, you can set it via SQL statements for creating users, ignoring MySQL privileges. |
mysql.native.password | |
// Goimport ("context"gohbase "cnb.woa.com/tdsql-hbase/tdsql-gohbase""cnb.woa.com/tdsql-hbase/tdsql-gohbase/hrpc")func main() {cfg := gohbase.TDSQLConfig{Endpoints: []string{"10.10.10.10:6752"}, // RPC port for the HBase serviceUsername: "test",Password: "test123",}client := gohbase.NewClient("", gohbase.WithTDSQLConfig(cfg))defer client.Close()// Writevalues := map[string]map[string][]byte{"cf": {"a": []byte{0}}}putRequest, _ := hrpc.NewPutStr(context.Background(), "table", "key", values)client.Put(putRequest)// ReadgetRequest, _ := hrpc.NewGetStr(context.Background(), "table", "key")client.Get(getRequest)}
Parameter | Description |
Endpoints | List of HBase service RPC port addresses, in the format ["host:port"]. |
Username | Database username |
Password | Database password |
Esta página foi útil?
Você também pode entrar em contato com a Equipe de vendas ou Enviar um tíquete em caso de ajuda.
comentários