Method 1:
/*** Add a row of Data ** @ Param tablename * Table name * @ Param columnfamily * column family name * @ Param rowkey * row key * @ Param columnqualifier * column qualifier * @ Param Value * value */Public void addrowdata (string tablename, string columnfamily, string rowkey, string columnqualifier, string value) {tablename = hbase_table_namespace + ":" + tablename; try {_ htableadmin = new htable (_ configuration, tablename ); put put = new put (bytes. tobytes (rowkey); Put. add (bytes. tobytes (columnfamily), bytes. tobytes (columnqualifier), bytes. tobytes (value); // when data changes, write the wal log put synchronously. setdurability (durability. sync_wal); _ htableadmin. put (Put);} catch (ioexception e) {e. printstacktrace ();} finally {This. closehtableadmin ("addrowdata ");}}
Method 2:
/*** Add a row of data with multiple delimiters ** @ Param tablename * Table name * @ Param columnfamily * column family * @ Param rowkey * row key * @ Param cqandvalue * column name (column qualifier) key-Value Pair */Public void addrowdata (string tablename, string columnfamily, string rowkey, Map <string, Object> cqandvalue) {If (cqandvalue. isempty () return; tablename = hbase_table_namespace + ":" + tablename; try {list <put> puts = new arraylist <put> (); For (string CQ: cqandvalue. keyset () {_ htableadmin = new htable (_ configuration, tablename); Put put = new put (bytes. tobytes (rowkey); Put. add (bytes. tobytes (columnfamily), bytes. tobytes (CQ), bytes. tobytes (cqandvalue. get (CQ ). tostring (); puts. add (Put);} _ htableadmin. put (puts);} catch (ioexception e) {e. printstacktrace ();} finally {This. closehtableadmin ("addrowdata ");}}
Call Method 1:
Hbasehelper. addrowdata (tablename, columnfamily, "3", "title", "quad-core I5 4570 litre 4590/gtx750 exclusive Computer Host game desktop DIY compatible machine"); hbasehelper. addrowdata (tablename, columnfamily, "3", "Introductions", "starting from the academic quarter, the exciting upgrade limited competition ① Free Upgrade ID-cooling se902 V3 dual-Copper Tube Blu-ray led high-end radiator, complete farewell to high temperature, crash, restart ② free upgrade to the first brand of rainbow gtx750 2G D5 high-end graphics cards ③ Free Upgrade of the world's first brand Asus B85M-F solid-state motherboard, exclusive EPU energy-saving and digital stable power supply, send National SF shipping! A limited quota of 300 servers is coming soon! "); Hbasehelper. addrowdata (tablename, columnfamily, "3", "price", 3699.00); hbasehelper. addrowdata (tablename, columnfamily, "3", "real", 2899.00); hbasehelper. addrowdata (tablename, columnfamily, "3", "freight", 0.00); hbasehelper. addrowdata (tablename, columnfamily, "3", "place", "Hubei Wuhan"); hbasehelper. addrowdata (tablename, columnfamily, "3", "monthame", 4469 );
Result 1:
2014-09-10 15:18:12, 777 warn [main] util. nativecodeloader (nativecodeloader. java: <clinit> (62)-unable to load native-hadoop library for your platform... using builtin-Java classes where applicable2014-09-10 15:18:12, 964 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: zookeeper. version = 3.4.6-1569965, built on 02/20/2014 15:18:12 GMT2014-09-10, 964 info [Mai N] zookeeper. zookeeper (environment. java: logenv (100)-client environment: host. name = [...] 2014-09-10 15:18:12, 964 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: Java. version = 1.7.0 _ 602014-09-10 15:18:12, 964 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: Java. vendor = Oracle Corporation2014-09-10 15:18:12, 964 info [main] zookeep Er. zookeeper (environment. java: logenv (100)-client environment: Java. home = D: \ Java \ jre72014-09-10 15:18:12, 964 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: Java. class. path = [...] 2014-09-10 15:18:12, 965 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: Java. library. path = [...] 2014-09-10 15:18:12, 965 info [main] zookeeper. zookeep Er (environment. java: logenv (100)-client environment: Java. io. tmpdir = [...] 2014-09-10 15:18:12, 965 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: Java. compiler = <Na> 15:18:12, 965 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: OS. name = Windows 72014-09-10 15:18:12, 965 info [main] zookeeper. zookeeper (environment. java: Logenv (100)-client environment: OS. arch = amd642014-09-10 15:18:12, 965 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: OS. version = 6.12014-09-10 15:18:12, 965 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: user. name = LFF2014-09-10 15:18:12, 965 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: US Er. home = [...] 2014-09-10 15:18:12, 965 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: user. dir = [...] 2014-09-10 15:18:12, 968 info [main] zookeeper. zookeeper (zookeeper. java: <init> (438)-initiating client connection, connectstring = 192.168.129.130: 2181 sessiontimeout = 90000 watcher = hconnection-0x7b70ad95, quorum = 192.168.129.130: 2181, baseznode =/hbase2014-09-10 15 8: 12, 999 info [main] zookeeper. recoverablezookeeper (recoverablezookeeper. java: <init> (120)-process identifier = hconnection-0x7b70ad95 connecting to zookeeper ensemble = 192.168.129.130: 21812014-09-10 15:18:12, 999 info [main-sendthread (192.168.129.130: 2181)] zookeeper. clientcnxn (clientcnxn. java: logstartconnect (975)-opening socket connection to server 192.168.129.130/192.168.129.130: 2181. will n Ot attempt to authenticate using SASL (unknown error) 15:18:13, 001 info [main-sendthread (192.168.129.130: 2181)] zookeeper. clientcnxn (clientcnxn. java: primeconnection (852)-socket connection established to 192.168.129.130/192.168.129.130: 2181, initiating session2014-09-10 15:18:13, 007 info [main-sendthread (192.168.129.130: 2181)] zookeeper. clientcnxn (clientcnxn. java: onconnected (1235 ))- Session establishment complete on server 192.168.129.130/192.168.129.130: 2181, sessionid = 0x1485d39e21a0015, negotiated timeout = 40000 hbase namespace exists [True]! Existshbasenamespace (...): Close the connection with hbase! Createhbasenamespace (...): Close the connection with hbase! Addrowdata (...): Close the connection with htable! Addrowdata (...): Close the connection with htable! Addrowdata (...): Close the connection with htable! Addrowdata (...): Close the connection with htable! Addrowdata (...): Close the connection with htable! Addrowdata (...): Close the connection with htable! Addrowdata (...): Close the connection with htable!
Call Method 2:
Map <string, Object> map = new hashmap <string, Object> (); map. put ("title", "Lenovo/Lenovo ideapad y400 Y400N-IFI (t) I5 game laptop 750 m"); map. put ("Introductions", "the powerful Y star and SSD performance"); map. put ("price", 5351.00); map. put ("real", 4649.00); map. put ("freight", 0); map. put ("place", "Beijing"); map. put ("monthper", 1329); hbasehelper. addrowdata (tablename, columnfamily, "2", MAP );
Result 2:
2014-09-10 15:05:20, 212 warn [main] util. nativecodeloader (nativecodeloader. java: <clinit> (62)-unable to load native-hadoop library for your platform... using builtin-Java classes where applicable2014-09-10 15:05:20, 401 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: zookeeper. version = 3.4.6-1569965, built on 02/20/2014 15:05:20 GMT2014-09-10, 401 info [Mai N] zookeeper. zookeeper (environment. java: logenv (100)-client environment: host. name = [...] 2014-09-10 15:05:20, 401 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: Java. version = 1.7.0 _ 602014-09-10 15:05:20, 401 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: Java. vendor = Oracle Corporation2014-09-10 15:05:20, 401 info [main] zookeep Er. zookeeper (environment. java: logenv (100)-client environment: Java. home = [...] 2014-09-10 15:05:20, 401 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: Java. class. path = [...] 2014-09-10 15:05:20, 402 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: Java. library. path = [...] 2014-09-10 15:05:20, 402 info [main] zookeeper. zookeeper (Env Ironment. java: logenv (100)-client environment: Java. io. tmpdir = [...] 2014-09-10 15:05:20, 402 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: Java. compiler = <Na> 15:05:20, 402 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: OS. name = Windows 72014-09-10 15:05:20, 402 info [main] zookeeper. zookeeper (environment. java: logenv ((100)-client environment: OS. arch = amd642014-09-10 15:05:20, 402 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: OS. version = 6.12014-09-10 15:05:20, 402 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: user. name = [...] 2014-09-10 15:05:20, 402 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: user. ho Me = [...] 2014-09-10 15:05:20, 403 info [main] zookeeper. zookeeper (environment. java: logenv (100)-client environment: user. dir = [...] 2014-09-10 15:05:20, 405 info [main] zookeeper. zookeeper (zookeeper. java: <init> (438)-initiating client connection, connectstring = 192.168.129.130: 2181 sessiontimeout = 90000 watcher = hconnection-0x265a7006, quorum = 192.168.129.130: 2181, baseznode =/hbase2014-09-10 15:05:20, 437 info [main] zookeeper. recoverablezookeeper (recoverablezookeeper. java: <init> (120)-process identifier = hconnection-0x265a7006 connecting to zookeeper ensemble = 192.168.129.130: 21812014-09-10 15:05:20, 437 info [main-sendthread (192.168.129.130: 2181)] zookeeper. clientcnxn (clientcnxn. java: logstartconnect (975)-opening socket connection to server 192.168.129.130/192.168.129.130: 2181. will not Tempt to authenticate using SASL (unknown error) 15:05:20, 439 info [main-sendthread (192.168.129.130: 2181)] zookeeper. clientcnxn (clientcnxn. java: primeconnection (852)-socket connection established to 192.168.129.130/192.168.129.130: 2181, initiating session2014-09-10 15:05:20, 445 info [main-sendthread (192.168.129.130: 2181)] zookeeper. clientcnxn (clientcnxn. java: onconnected (1235)-sess Ion establishment complete on server 192.168.129.130/192.168.129.130: 2181, sessionid = 0x1485d39e21a0014, negotiated timeout = 40000 hbase namespace exists [True]! Existshbasenamespace (...): Close the connection with hbase! Createhbasenamespace (...): Close the connection with hbase! Addrowdata (...): Close the connection with htable!
The comparison shows that the communication between the C end and the S end is basically understood!
Simple comparison of hbase put