import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table; public class HBaseTest2 {
public static Configuration configuration;
public static Connection connection;
public static Admin admin; public static void main(String[] args) {
configuration=HBaseConfiguration.create();
configuration.set("hbase.rootdir", "hdfs://localhost:9000/hbase"); /*
try {
connection=ConnectionFactory.createConnection(configuration);
admin=connection.getAdmin();
insertRow("Student","scofield","score","English","45");
insertRow("Student","scofield","score","Math","89");
insertRow("Student","scofield","score","Computer","100");
System.out.println("插入成功!---李运辰");
} catch (IOException e) {
e.printStackTrace();
}
*/
configuration.set("hbase.rootdir", "hdfs://localhost:9000/hbase");
try {
connection=ConnectionFactory.createConnection(configuration);
admin=connection.getAdmin();
getData("Student","scofield","score","English");
System.out.println("输出完成!---李运辰");
} catch (IOException e) {
e.printStackTrace();
} close();
} public static void insertRow(String tableName, String rowKey, String colFamily, String col, String val) {
try {
Table table = connection.getTable(TableName.valueOf(tableName));
Put put = new Put(rowKey.getBytes());
put.addColumn(colFamily.getBytes(), col.getBytes(), val.getBytes());
table.put(put);
table.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } public static void getData(String tableName, String rowKey, String colFamily, String col) {
try {
Table table = connection.getTable(TableName.valueOf(tableName));
Get get=new Get(rowKey.getBytes());
get.addColumn(colFamily.getBytes(), col.getBytes());
Result result=table.get(get);
showCell(result);
table.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } private static void showCell(Result result) {
Cell[] cells=result.rawCells();
for(Cell cell:cells) {
System.out.println("RowName:"+new String(CellUtil.cloneRow(cell))+" ");
System.out.println("Timetamp:"+cell.getTimestamp()+" ");
System.out.println("column Family"+new String(CellUtil.cloneFamily(cell))+" ");
System.out.println("row Name:"+new String(CellUtil.cloneValue(cell))+" ");
System.out.println("value"+new String(CellUtil.cloneValue(cell))+" "); } }
public static void close() { try {
if (admin != null) {
admin.close();
}
if(null!=connection) {
connection.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } }

Java_Habse_add的更多相关文章

随机推荐

  1. Ehcache缓存框架与 Shiro 框架 出现出现验证错误 && Tomcat 缓存清除的问题

    当一个项目使用久了以后就会出现各种问题,下面是我遇到的一个权限验证错误的问题 我的项目是   Ehcache 结合 Shiro  一起使用的,项目用用久了出现   Token验证错误,Cookie之类 ...

  2. CSS的快速入门

    CSS的快速入门 1.CSS要学习的内容主要包括 1. CSS概念和快速入门 2.CSS选择器(重点+难点) 3.美化网页(文字.阴影.超链接.列表.渐变,等) 4.盒子模型 5.浮动 6.定位 2. ...

  3. 算法竞赛入门经典第二版 蛇形填数 P40

    #include<bits/stdc++.h> using namespace std; #define maxn 20 int a[maxn][maxn]; int main(){ ; ...

  4. K3/Cloud点按钮打开单据,列表,动态表单,简单账表和直接Sql报表示例

    BOS IDE中配置了个界面,拖了动态表单界面,加了5个测试按钮. 点击“打开单据”维护界面, 会跳转到一个新的主界面页签,[物料]新增 点击“打开列表”,会弹出[物料]列表界面 点击“打开动态表单” ...

  5. oracle 数据库手动备份和恢复

    一.备份命令: 1.cmd  : exp 2.cmd  :用户名/密码@ip地址/数据库名  如:     yyj/yyj@172.12.5.5/orcl    要导出的数据库 3.回车:输入要输出的 ...

  6. Linux package installation: deb and rpm

    一般来说著名的 Linux 系统基本上分两大类: RedHat 系列:Redhat.Centos.Fedora 等 Debian 系列:Debian.Ubuntu 等 Dpkg (Debian系): ...

  7. Allegro 串扰仿真

    利用于博士的那个电路板,看一下cadence软件的串扰仿真,我们选取3跟信号线,见下图. U6.N3-R36-U7.56 U6.P3-R36-U7.54 U6.P2-R36-U7.53 下面启动sig ...

  8. 1015 Reversible Primes

    1. 题目 2. 抽象建模 无 3. 方法 无 4. 注意点 素数判断(1不是素数) 数值的倒转 5. 代码 #include<stdio.h> #include<math.h> ...

  9. 题解【洛谷P1807】最长路_NOI导刊2010提高(07)

    题面 题解 最长路模板. 只需要在最短路的模板上把符号改一下\(+\)初值赋为\(-1\)即可. 注意一定是单向边,不然出现了正环就没有最长路了,就好比出现了负环就没有最短路了. 只能用\(SPFA\ ...

  10. 测试理论 - Test Double

    概述 简述 test double mock, fake 之类的东西 背景 最近在看 google 软件测试之道 妈的 13 年的老书了 书里有提到 mock, fake, stub 刚好, 我又不太 ...