public class CreateHbaseDemo {
public static void main(String[] args) throws IOException {
//我自己已经写好帮助类HBaseHelper,把hbase的连接配置信息放到帮助类里面了,
//这里需要你自己配好自己的配置,
//不会的可以参考下面的参考文档,这位博主写的很好
Connection connection = HBaseHelper.getConnection();
insertData(connection,"Hbase_Indexer_Test","2019","cf1","publish_time","20190904");
insertData(connection,"Hbase_Indexer_Test","2019","cf1","id","2019");
insertData(connection,"Hbase_Indexer_Test","2019","cf1","headline","20190905");
System.out.println("添加成功!!");
}
public static void insertData (Connection connection,String tableName,String rowkey,String colFamily,String col,String val) throws IOException {
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();
}
}
参考文档:https://blog.csdn.net/a973685825/article/details/81303636