释放双眼,带上耳机,听听看~!
已经创建了一个学生宿舍管理系统
数据表表名:student_info
列族1:students
列族2:dormitorys
列族3:staff_members
将行键为001的dormits列族下的列名为hostel No.的数据更改为115:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 1package myhbase;
2
3import java.io.IOException;
4
5import org.apache.hadoop.conf.Configuration;
6import org.apache.hadoop.hbase.client.Put;
7import org.apache.hadoop.hbase.HBaseConfiguration;
8import org.apache.hadoop.hbase.client.HBaseAdmin;
9import org.apache.hadoop.hbase.client.HTable;
10import org.apache.hadoop.hbase.util.Bytes;
11
12public class UpdateData {
13 public static void main(String[] args) throws IOException{
14 updatedata("student_info");
15 }
16
17 public static void updatedata(String tableName) throws IOException{
18
19 Configuration conf = HBaseConfiguration.create();
20 HTable hTable = new HTable(conf,"student_info");
21
22 org.apache.hadoop.hbase.client.Put p = new Put(Bytes.toBytes("001"));
23 //Updating
24 p.add(Bytes.toBytes("dormitorys"),
25 Bytes.toBytes("hostel_No."),Bytes.toBytes("115"));
26 //save
27 hTable.put(p);
28 System.out.println("data Updated!");
29 hTable.close();
30 }
31
32}
33
34