首批通过分布式安全可靠测评,为关键业务系统打造
OBKV-Table Java 客户端使用示例
更新时间:2024-10-28 23:00:00
本文将给出一个客户端使用的示例,您可参考示例使用 OBKV-Table 客户端。
创建 Table
CREATE TABLE IF NOT EXISTS `test_varchar_table` (
`c1` varchar(20) NOT NULL,
`c2` varchar(20) DEFAULT NULL,
PRIMARY KEY (`c1`)
);
单集群执行
ObTableClient client = new ObTableClient();
// username
client.setFullUserName("your user name");
// password
client.setPassword("your passwd");
// config url
client.setParamURL("your OCP addr");
obTableClient.setSysUserName("your sys user name");
obTableClient.setSysPassword("your sys password");
client.init();
// 1. single execute
// return affectedRows
client.insert("test_varchar_table", "foo", new String[] { "c2" },
new String[] { "bar" });
// return Map<String, Object>
client.get("test_varchar_table", "foo", new String[] { "c2" });
// return affectedRows
client.delete("test_varchar_table", "foo");
// 2. batch execute
TableBatchOps batchOps = client.batch("test_varchar_table");
batchOps.insert("foo", new String[] { "c2" },
new String[] { "bar" });
batchOps.get("foo", new String[] { "c2" });
batchOps.delete("foo");
List<Object> results = batchOps.execute();
// 1. affectedRows; 2. Map; 3. affectedRows