所需要的包有:
commons-codec-1.4.jar
commons-logging-1.1.1.jar
hadoop-0.20.2-core.jar
hbase-0.90.2.jar
log4j-1.2.16.jar
zookeeper-3.3.2.jar
背景:
假设有一个不知道是干什么表:)
表里需要存入人员和其相对应的部门信息
代码:
import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
public class HbaseAddEdtDel {
public static Configuration configuration=null;
static {
configuration = HBaseConfiguration.create();
configuration.set("hbase.master", "192.168.0.201:60000");
configuration.set("hbase.zookeeper.quorum","192.168.0.201,192.168.0.202,192.168.0.203");
configuration.set("hbase.zookeeper.property.clientPort", "2181");
}
public static void main(String[] args) throws Exception {
HBaseAdmin admin = new HBaseAdmin(configuration);
if (admin.tableExists("riapguh")) {
System.out.println("删除 table");
admin.disableTable("riapguh");
admin.deleteTable("riapguh");
}
//创建riapguh表
System.out.println("创建 table");
HTableDescriptor tableDescripter = new HTableDescriptor("riapguh".getBytes());//创建表
tableDescripter.addFamily(new HColumnDescriptor("user"));//创建列簇user
tableDescripter.addFamily(new HColumnDescriptor("dpt"));//创建列簇dpt
admin.createTable(tableDescripter);
HTable table = new HTable(configuration, "riapguh");
//插入数据
System.out.println("add riapguh data");
List<Put> putuser = new ArrayList<Put>();
Put user1 = new Put(new String("用户A").getBytes());
//写入用户员信息
user1.add(new String("user").getBytes(), new String("user_code").getBytes(), new String("u_0001").getBytes());
user1.add(new String("user").getBytes(), new String("user_name").getBytes(), new String("u_用户A").getBytes());
//写入部门信息
user1.add(new String("dpt").getBytes(), new String("dpt_code").getBytes(), new String("d_001").getBytes());
user1.add(new String("dpt").getBytes(), new String("dpt_name").getBytes(), new String("d_部门A").getBytes());
putuser.add(user1);
Put user2 = new Put(new String("用户B").getBytes());
//写入用户员信息
user2.add(new String("user").getBytes(), new String("user_code").getBytes(), new String("u_0002").getBytes());
user2.add(new String("user").getBytes(), new String("user_name").getBytes(), new String("u_用户B").getBytes());
//写入部门信息
user2.add(new String("dpt").getBytes(), new String("dpt_code").getBytes(), new String("d_002").getBytes());
user2.add(new String("dpt").getBytes(), new String("dpt_name").getBytes(), new String("d_部门B").getBytes());
putuser.add(user2);
Put user3 = new Put(new String("用户C").getBytes());
//写入用户员信息
user3.add(new String("user").getBytes(), new String("user_code").getBytes(), new String("u_0003").getBytes());
user3.add(new String("user").getBytes(), new String("user_name").getBytes(), new String("u_用户C").getBytes());
//写入部门信息
user3.add(new String("dpt").getBytes(), new String("dpt_code").getBytes(), new String("d_003").getBytes());
user3.add(new String("dpt").getBytes(), new String("dpt_name").getBytes(), new String("d_部门C").getBytes());
putuser.add(user3);
table.put(putuser);
table.flushCommits();
//更新用户B
Put updateb = new Put(new String("用户B").getBytes());
//写入用户员信息
updateb.add(new String("user").getBytes(), new String("user_code").getBytes(), new String("u_000xsx").getBytes());
updateb.add(new String("user").getBytes(), new String("user_name").getBytes(), new String("u_用户xsx").getBytes());
//写入部门信息
updateb.add(new String("dpt").getBytes(), new String("dpt_code").getBytes(), new String("d_00xsx").getBytes());
updateb.add(new String("dpt").getBytes(), new String("dpt_name").getBytes(), new String("d_部门xsx").getBytes());
table.put(updateb);
table.flushCommits();
//HBaseBasic.selectByRowKey("riapguh");
System.out.println("-------------删除用户C---------------------");
//删除用户C
//able.delete(new Delete(new String("用户C").getBytes()));
List<Delete> deld = new ArrayList<Delete>();
deld.add(new Delete(new String("用户C").getBytes()));
table.delete(deld);
table.flushCommits();
//HBaseBasic.selectByRowKey("riapguh");
}
}
分享到:
相关推荐
假设有一个不知道是干什么表:) 表里需要存入人员和其相对应的部门信息 HBaseAdmin admin = new HBaseAdmin(configuration); List<Put> putuser = new ArrayList();
hbase-0.90.5.tar.gz与hadoop0.20.2版本匹配,我在我本地虚拟机已经安装成功可以使用。请放心下载!!!
HBase 元数据修复工具包。 ①修改 jar 包中的application.properties,重点是 zookeeper.address、zookeeper.nodeParent、hdfs.root.dir配置项,hdfs 最好写 ip; ②将core-site.xml、hdfs-site.xml添加到BOOT-INF/...
并提供了以类SQL的方式来读写HBase表中的数据。对HBase的API做了一层抽象,统一了HBase1.x和HBase2.x的实现,并提供了读写HBase的ORM的支持,同时,sdk还对HBase thrift 的客户端API进行了池化封装,(类似JedisPool...
HBase(hbase-2.4.9-bin.tar.gz)是一个分布式的、面向列的开源数据库,该技术来源于 Fay Chang 所撰写的Google论文“Bigtable:一个结构化数据的分布式存储系统”。就像Bigtable利用了Google文件系统(File System...
hbase的hbase-1.2.0-cdh5.14.2.tar.gz资源包
被编译的hive-hbase-handler-1.2.1.jar,用于在Hive中创建关联HBase表的jar,解决创建Hive关联HBase时报FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. org.apache.hadoop....
hbase-client-2.1.0-cdh6.3.0.jar
HBase是一个分布式的、面向列的开源数据库,该技术来源于 Fay Chang 所撰写的Google论文“Bigtable:一个结构化数据的分布式存储系统”。就像Bigtable利用了Google文件系统(File System)所提供的分布式数据存储...
phoenix-hbase-2.2-5.1.2-bin.tar.gz
赠送jar包:hbase-hadoop-compat-1.1.3.jar; 赠送原API文档:hbase-hadoop-compat-1.1.3-javadoc.jar; 赠送源代码:hbase-hadoop-compat-1.1.3-sources.jar; 赠送Maven依赖信息文件:hbase-hadoop-compat-1.1.3....
phoenix-client-hbase-2.2-5.1.2.jar
赠送jar包:hbase-prefix-tree-1.1.3.jar; 赠送原API文档:hbase-prefix-tree-1.1.3-javadoc.jar; 赠送源代码:hbase-prefix-tree-1.1.3-sources.jar; 赠送Maven依赖信息文件:hbase-prefix-tree-1.1.3.pom; ...
hbase-2.0.2-bin.tar
hbase-1.2.6.1-bin.tar.gz,hbase-1.2.6.1-bin.tar.gz,hbase-1.2.6.1-bin.tar.gz,hbase-1.2.6.1-bin.tar.gz,hbase-1.2.6.1-bin.tar.gz,hbase-1.2.6.1-bin.tar.gz,hbase-1.2.6.1-bin.tar.gz,hbase-1.2.6.1-bin.tar.gz
赠送jar包:hbase-metrics-api-1.4.3.jar; 赠送原API文档:hbase-metrics-api-1.4.3-javadoc.jar; 赠送源代码:hbase-metrics-api-1.4.3-sources.jar; 赠送Maven依赖信息文件:hbase-metrics-api-1.4.3.pom; ...
hbase-1.2.1-bin.tar.gz.zip 提示:先解压再使用,最外层是zip压缩文件
赠送jar包:hbase-annotations-1.1.2.jar; 赠送原API文档:hbase-annotations-1.1.2-javadoc.jar; 赠送源代码:hbase-annotations-1.1.2-sources.jar; 赠送Maven依赖信息文件:hbase-annotations-1.1.2.pom; ...
赠送jar包:hbase-client-1.4.3.jar; 赠送原API文档:hbase-client-1.4.3-javadoc.jar; 赠送源代码:hbase-client-1.4.3-sources.jar; 赠送Maven依赖信息文件:hbase-client-1.4.3.pom; 包含翻译后的API文档:...