java

位置:IT落伍者 >> java >> 浏览文章

java应用程序put操作


发布日期:2023年12月12日
 
java应用程序put操作

创建表

put操作

public class myHbase {

private static Configuration conf= null;

static {

conf=HBaseConfigurationcreate()

}

/**

* column familys add column <>hbase columnName

* @param tableName

* @param familys

* @throws Exception

*/

public void createTable(String tableNameString[] familys) throws Exception{

HBaseAdmin admin = new HBaseAdmin(conf)

if(!admintableExists(tableName)){

HTableDescriptor desc = new HTableDescriptor(tableName)

for (int i = ; i < familyslength; i++) {

descaddFamily(new HColumnDescriptor(familys[i]))

}

admincreateTable(desc)

}else{

Systemoutprintln(the table:+ tableName + exsists

};

}

/**

* @param tableName

* @param rowKey

* @param family

* @param qualifier

* @param value

* @throws Exception

*/

public void putData(String tableNameString rowKey String family

String qualifier String value) throws Exception {

HTable ht = new HTable(conf tableName)

Put put = new Put(BytestoBytes(rowKey))

putadd(BytestoBytes(family) BytestoBytes(qualifier) BytestoBytes(value))

htput(put)

}

public static void main(String [] agrs) throws Exception{

myHbase h= new myHbase()

String [] familys = {familyfamily};

hcreateTable(mytable familys)

hputData(mytable row family qualifier:name value

}

}

运行java应用程序登录hbase shell 发现可以get和scan到数据了

hbase(main):> scan mytable

ROW COLUMN+CELL

row column=family:qualifier:name timestamp= v

alue=value

row(s) in seconds

hbase(main):> get mytablerowfamily:qualifier:name

COLUMN CELL

family:qualifier:na timestamp= value=value

me

row(s) in seconds

               

上一篇:Java动态代理机制综合分析及扩展

下一篇:java程序异常处理方法