In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "creating tables, inserting data, updating data, and deleting data in hbase". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The required packages are:
Commons-codec-1.4.jar
Commons-logging-1.1.1.jar
Hadoop-0.20.2-core.jar
Hbase-0.90.2.jar
Log4j-1.2.16.jar
Zookeeper-3.3.2.jar
Background:
Suppose there is a table that does not know what it is:)
The personnel and their corresponding department information need to be stored in the table.
Code:
Import java.util.ArrayList;import java.util.List;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.hadoop.hbase.HColumnDescriptor;import org.apache.hadoop.hbase.HTableDescriptor;import org.apache.hadoop.hbase.client.Delete;import org.apache.hadoop.hbase.client.HBaseAdmin;import org.apache.hadoop.hbase.client.HTable;import org.apache.hadoop.hbase.client.Put; public class HbaseAddEdtDel {public static Configuration configuration=null; static {configuration= HBaseConfiguration.create () Configuration.set ("hbase.master", "192.168.0.201 hbase.zookeeper.quorum"); configuration.set ("hbase.zookeeper.quorum", "192.168.0.201192.168.0.203"); configuration.set ("hbase.zookeeper.property.clientPort", "2181");} public static void main (String [] args) throws Exception {HBaseAdmin admin = new HBaseAdmin (configuration) If (admin.tableExists ("riapguh")) {System.out.println ("delete table"); admin.disableTable ("riapguh"); admin.deleteTable ("riapguh");} / / create riapguh table System.out.println ("create table"); HTableDescriptor tableDescripter = new HTableDescriptor ("riapguh" .getBytes ()) / / create table tableDescripter.addFamily (new HColumnDescriptor ("user")); / / create column cluster user tableDescripter.addFamily (new HColumnDescriptor ("dpt")); / / create column cluster dpt admin.createTable (tableDescripter); HTable table = new HTable (configuration, "riapguh"); / / insert data System.out.println ("add riapguh data"); List putuser = new ArrayList () Put user1 = new Put (new String ("user A"). GetBytes (); / / write user information user1.add (new String ("user"). GetBytes (), new String ("user_code"). GetBytes (), new String ("user 0001"). GetBytes ()) User1.add (new String ("user"). GetBytes (), new String ("user_name"). GetBytes (), new String ("u _ user A"). GetBytes (); / / write department information user1.add (new String ("dpt"). GetBytes (), new String ("dpt_code"). GetBytes (), new String ("dumb001"). GetBytes ()) User1.add (new String ("dpt"). GetBytes (), new String ("dpt_name"). GetBytes (), new String ("d _ department A"). GetBytes (); putuser.add (user1); Put user2 = new Put (new String ("user B"). GetBytes ()) / write user information user2.add (new String ("user"). GetBytes (), new String ("user_code"). GetBytes (), new String ("upri0002"). GetBytes (); user2.add (new String ("user"). GetBytes (), new String ("user_name"). GetBytes (), new String ("u _ user B"). GetBytes ()) / write department information user2.add (new String ("dpt"). GetBytes (), new String ("dpt_code"). GetBytes (), new String ("dumb002"). GetBytes (); user2.add (new String ("dpt"). GetBytes (), new String ("dpt_name"). GetBytes (), new String ("d _ department B"). GetBytes (); putuser.add (user2) Put user3 = new Put (new String ("user C"). GetBytes ()); / / write user information user3.add (new String ("user"). GetBytes (), new String ("user_code"). GetBytes (), new String ("user 0003"). GetBytes ()) User3.add (new String ("user"). GetBytes (), new String ("user_name"). GetBytes (), new String ("u _ user C"). GetBytes (); / write department information user3.add (new String ("dpt"). GetBytes (), new String ("dpt_code"). GetBytes (), new String ("dumb003"). GetBytes ()) User3.add (new String ("dpt"). GetBytes (), new String ("dpt_name"). GetBytes (), new String ("d _ department C"). GetBytes (); putuser.add (user3); table.put (putuser); table.flushCommits (); / / update user B Put updateb = new Put (new String ("user B"). GetBytes ()) / write user information updateb.add (new String ("user"). GetBytes (), new String ("user_code"). GetBytes (), new String ("u_000xsx"). GetBytes (); updateb.add (new String ("user"). GetBytes (), new String ("user_name"). GetBytes (), new String ("u _ user xsx"). GetBytes ()) / write department information updateb.add (new String ("dpt"). GetBytes (), new String ("dpt_code"). GetBytes (), new String ("d_00xsx"). GetBytes (); updateb.add (new String ("dpt"). GetBytes (), new String ("dpt_name"). GetBytes (), new String ("ddepartment xsx"). GetBytes (); table.put (updateb); table.flushCommits () / / HBaseBasic.selectByRowKey ("riapguh"); System.out.println ("- Delete user C -"); / / Delete user C / / able.delete (new Delete (new String ("user C"). GetBytes ()); List deld = new ArrayList () Deld.add (new Delete (new String ("user C"). GetBytes ()); table.delete (deld); table.flushCommits (); / / HBaseBasic.selectByRowKey ("riapguh");}} "the operation of creating tables, inserting data, updating data, and deleting data in hbase" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.