Hbase API 写入操作代码,基于hbase-client 1.0.3版本
<dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-client</artifactId> <version>1.0.3</version> </dependency>
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.BufferedMutator; import org.apache.hadoop.hbase.client.BufferedMutatorParams; 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.client.Table; import org.apache.hadoop.hbase.util.Bytes; import java.io.IOException; public class HbaseTest01 { public static void main(String[] args) throws IOException{ TableName name = TableName.valueOf("testtable"); Configuration conf = HBaseConfiguration.create(); Connection connection = ConnectionFactory.createConnection(conf); Table table = connection.getTable(name); BufferedMutator mutator = connection.getBufferedMutator(name); for (int i = 0; i < 1000000; i++){ String rowStr = "row"+i; String valStr = "val"+i; Put put = new Put(Bytes.toBytes(rowStr)); put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"), Bytes.toBytes(valStr)); mutator.mutate(put); } mutator.close(); table.close(); connection.close(); System.out.println("done!"); } }