This topic provides an example to describe how to use the TableAPI client.
Create a table
CREATE TABLE IF NOT EXISTS `test_varchar_table` (
`c1` varchar(20) NOT NULL,
`c2` varchar(20) DEFAULT NULL,
PRIMARY KEY (`c1`)
);
Use the client on a single cluster
ObTableClient client = new ObTableClient();
// Specify the username
client.setFullUserName("your user name");
// Specify the password
client.setPassword("your passwd");
// Configure the URL
client.setParamURL("your OCP addr");
obTableClient.setSysUserName("your sys user name");
obTableClient.setSysPassword("your sys password");
client.init();
// 1. 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