hbase编程demo
1.在Buildpath添加需要引起用的jar,hbase的软件lib文件下的所有jar
2.创建好一个列名为:c1,c2的表,表名:hbase_table1
import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.HConnection; import org.apache.hadoop.hbase.client.HConnectionManager; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Put; public class demo { public static Configuration configuration; static { configuration = HBaseConfiguration.create(); configuration.set("hbase.zookeeper.property.clientPort", "2181"); configuration.set("hbase.zookeeper.quorum", "hbase的master"); } public static void main(String[] args) throws Exception { System.out.println("start insert data ......"); HConnection con=HConnectionManager.createConnection(configuration); HTable table = (HTable)con.getTable("hbase_table1"); Put put = new Put("1".getBytes());// 一个PUT代表一行数据,再NEW一个PUT表示第二行数据,每行一个唯一的ROWKEY, put.add("c1".getBytes(), null, "百度".getBytes());// 本行数据的第一列 put.add("c2".getBytes(), null, "http://www.baidu.com1".getBytes());// 本行数据的第二列 try { table.put(put); } catch (IOException e) { e.printStackTrace(); } System.out.println("end insert data ......"); } }3.进入bin/hbase shell,输入scan "hbase_table1"查看数据