HBase 詳細API操作

2021-10-05 12:40:38 字數 2549 閱讀 9914

新建專案後在pom.xml中新增依賴:

>

>

org.apache.hbasegroupid

>

>

hbase-serverartifactid

>

>

1.3.1version

>

dependency

>

>

>

org.apache.hbasegroupid

>

>

hbase-clientartifactid

>

>

1.3.1version

>

dependency

>

>

>

jdk.toolsgroupid

>

>

jdk.toolsartifactid

>

>

1.8version

>

>

systemscope

>

>

$/lib/tools.jarsystempath

>

dependency

>

獲取configuration物件
public

static configuration conf;

static

判斷表是否存在
public

static

boolean

istableexist

(string tablename)

throws masternotrunningexception,

zookeeperconnectionexception, ioexception

建立表
public

static

void

createtable

(string tablename, string.

.. columnfamily)

throws

masternotrunningexception, zookeeperconnectionexception, ioexception

else

//根據對錶的配置,建立表

admin.

createtable

(descriptor)

; system.out.

println

("表"

+ tablename +

"建立成功!");

}}

刪除表
public

static

void

droptable

(string tablename)

throws masternotrunningexception,

zookeeperconnectionexception, ioexception

else

}

向表中插入資料
public

static

void

addrowdata

(string tablename, string rowkey, string columnfamily, string

column, string value)

throws ioexception

刪除多行資料
public

static

void

deletemultirow

(string tablename, string.

.. rows)

throws ioexception

htable.

delete

(deletelist)

; htable.

close()

;}

獲取所有資料
public

static

void

getallrows

(string tablename)

throws ioexception

}}

獲取某一行資料
public

static

void

getrow

(string tablename, string rowkey)

throws ioexception

}

獲取某一行指定「列族:列」的資料
public

static

void

getrowqualifier

(string tablename, string rowkey, string family, string

qualifier)

throws ioexception

}

csdn:

Hbase常用api操作

連線資料庫 configuration conf new configuration conf.set hbase.zookeeper.quorum node01 2181,node02 2181,node03 2181 connection connection connectionfactory...

Hbase學習02 API操作

重要的部分 1.建立hbase連線以及admin管理物件 要操作hbase也需要建立hbase的連線,此處我們仍然使用testng來進行測試,使用 beforetest初始化hbase的連線,然後建立admin的物件,aftertest來關閉連線 實現步驟 1.1使用hbaseconfigurati...

HBase核心開發API

初始化 配置資訊 before public void init catch exception e 關閉資源 after public void close catch ioexception e if connection null catch ioexception e 建立命名空間 test...