Criado por Rafael Dick , Raphael Rodrigues e Tialles Zerwes
public class CreateTable {
public static void main(String[] args) throws IOException {
// Instantiating configuration class
Configuration con = HBaseConfiguration.create();
// Instantiating HbaseAdmin class
HBaseAdmin admin = new HBaseAdmin(con);
// Instantiating table descriptor class
HTableDescriptor tableDescriptor = new
TableDescriptor(TableName.valueOf("emp"));
// Adding column families to table descriptor
tableDescriptor.addFamily(new HColumnDescriptor("personal"));
tableDescriptor.addFamily(new HColumnDescriptor("professional"));
// Execute the table through admin
admin.createTable(tableDescriptor);
}
}
public class InsertData{
public static void main(String[] args) throws IOException {
// Instantiating Configuration class and Instantiating HTable class
Configuration config = HBaseConfiguration.create();
HTable hTable = new HTable(config, "emp");
// Instantiating Put class accepts a row name.
Put p = new Put(Bytes.toBytes("row1"));
// add values using add() method
// accepts column family name, qualifier/row name ,value
p.add(Bytes.toBytes("personal"),Bytes.toBytes("name"),Bytes.toBytes("raju"));
p.add(Bytes.toBytes("personal"),p.add(Bytes.toBytes("professional"),
Bytes.toBytes("manager"));
// Saving the put Instance to the HTable and closing HTable
hTable.put(p);
hTable.close();
}
}
public class InsertData{
public static void main(String[] args) throws IOException {
// Instantiating Configuration class and Instantiating HTable class
Configuration config = HBaseConfiguration.create();
HTable hTable = new HTable(config, "emp");
// Instantiating Put class accepts a row name.
Put p = new Put(Bytes.toBytes("row1"));
// Updating a cell value
p.add(Bytes.toBytes("personal"),
Bytes.toBytes("city"),Bytes.toBytes("Delih"));
// Saving the put Instance to the HTable and closing HTable
hTable.put(p);
hTable.close();
}
}
public class InsertData{
public static void main(String[] args) throws IOException {
// Instantiating Configuration class and Instantiating HTable class
Configuration config = HBaseConfiguration.create();
HTable hTable = new HTable(config, "emp");
// Instantiating Get class
Get g = new Get(Bytes.toBytes("row1"));
// Reading the data
Result result = table.get(g);
// Reading values from Result class object
byte [] value = result.getValue(Bytes.toBytes("personal"),
Bytes.toBytes("name"));
byte [] value1 = result.getValue(Bytes.toBytes("personal"),
Bytes.toBytes("city"));
}
}
public class InsertData{
public static void main(String[] args) throws IOException {
// Instantiating Configuration class and Instantiating HTable class
Configuration config = HBaseConfiguration.create();
HTable hTable = new HTable(config, "emp");
// Instantiating Delete class
Delete delete = new Delete(Bytes.toBytes("row1"));
delete.deleteColumn(Bytes.toBytes("personal"), Bytes.toBytes("name"));
delete.deleteFamily(Bytes.toBytes("professional"));
// deleting the data
table.delete(delete);
// closing the HTable object
table.close();
}
}