1. 程式人生 > >Java程式碼為hbase表新增資料

Java程式碼為hbase表新增資料

說到給hbase表新增資料,不得不說put

public static void addRecord (String tableName, String rowKey, String family, String qualifier, String value)    
            throws Exception{    
        try {    
            HTable table = new HTable(con, tableName);    
            Put put = new Put(Bytes.toBytes(rowKey));    
            put.add(Bytes.toBytes(family),Bytes.toBytes(qualifier),Bytes.toBytes(value));    
            table.put(put);    
            System.out.println("insert recored " + rowKey + " to table " + tableName +" ok.");    
        } catch (IOException e) {    
            e.printStackTrace();    
        }    
    }