<dependencies>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
</dependency>
</dependencies>
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.annotations.HBaseEntity;
import org.apache.hadoop.hbase.annotations.HBaseTable;
import org.apache.hadoop.hbase.annotations.HBaseColumn;
@HBaseEntity(tableName = "my_table")
@HBaseTable(family = "my_family")
public class MyEntity {
@HBaseColumn(qualifier = "column1")
private String column1;
public void setColumn1(String column1) {
this.column1 = column1;
}
public Put toPut(String rowKey) {
Put put = new Put(Bytes.toBytes(rowKey));
put.addColumn(Bytes.toBytes("my_family"), Bytes.toBytes("column1"), Bytes.toBytes(column1));
return put;
}
}
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.TableName;
public class Example {
public static void main(String[] args) {
Configuration config = HBaseConfiguration.create();
try (Connection connection = ConnectionFactory.createConnection(config);
Table table = connection.getTable(TableName.valueOf("my_table"))) {
MyEntity entity = new MyEntity();
entity.setColumn1("Value 1");
table.put(entity.toPut("rowKey"));
} catch (Exception e) {
e.printStackTrace();
}
}
}