3.3 删除表
import
org.apache.kudu.client.KuduClient;
import
org.apache.kudu.client.KuduException;
public
class DropTable {
public
static void main(String[] args) throws KuduException {
String
masterAddress = "hadoop102,hadoop103,hadoop104";
KuduClient
client = new
KuduClient.KuduClientBuilder(masterAddress).defaultSocketReadTimeoutMs(6000).build();
try
{
client.deleteTable("student");
}
catch (KuduException e) {
e.printStackTrace();
}
finally {
client.close();
}
}
}
3.4 插入数据
import
org.apache.kudu.client.*;
public
class InsertRow {
public
static void main(String[] args) throws KuduException {
String
masterAddr = "hadoop102,haoop103,hadoop104";
KuduClient
client = new
KuduClient.KuduClientBuilder(masterAddr).defaultSocketReadTimeoutMs(6000).build();
try
{
KuduTable
table = client.openTable("student");
KuduSession
kuduSession = client.newSession();
kuduSession.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH);
kuduSession.setMutationBufferSpace(3000);
for
(int i = 1; i < 10; i++) {
Insert
insert = table.newInsert();
insert.getRow().addInt("id",
i);
insert.getRow().addString("name",
i + "号");
kuduSession.flush();
kuduSession.apply(insert);
}
kuduSession.close();
}
catch (KuduException e) {
e.printStackTrace();
}
finally {
client.close();
}
}
}
本教程由尚硅谷教育大数据研究院出品,如需转载请注明来源,欢迎大家关注尚硅谷公众号(atguigu)了解更多。
加载中,请稍候......