In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1. Modify hosts file
Enter the C:\ Windows\ System32\ drivers\ etc directory
Edit the hosts file and add 10.10.10.10 (to be the same as ip in hosts in linux machine) hbase at the bottom
Save exit
2. Install maven (easy to manage jar package or not)
For specific installation steps, please refer to http://blog.csdn.net/chenxuejiakaren/article/details/7938524
For installation in eclipse, please refer to http://blog.csdn.net/wode_dream/article/details/38052639
Third, create a project
New-> Project-> Select maven project- under maven folder > Type selection maven-archetype-quickstart- >
Group id is combined with artifact id to make a complete package. Generally, artifact id is the project name-> after it is built, double-click pom.xml- > switch to the last card pom.xml- >
Add such a section to the dependencies
Org.apache.hbase
Hbase-client
0.98.9-hadoop2
Save it and OK it!
If an error is reported:
Missing artifact jdk.tools:jdk.tools
Add this part.
Jdk.tools
Jdk.tools
1.8
System
${JAVA_HOME} / lib/tools.jar
4. Operate hbase
Create a new class under the package
Note that the call should be made directly
DBhelper. Method ()
Package package name; import java.io.IOException;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.HColumnDescriptor;import org.apache.hadoop.hbase.HTableDescriptor;import org.apache.hadoop.hbase.KeyValue;import org.apache.hadoop.hbase.MasterNotRunningException;import org.apache.hadoop.hbase.ZooKeeperConnectionException;import org.apache.hadoop.hbase.client.Get;import org.apache.hadoop.hbase.client.HBaseAdmin;import org.apache.hadoop.hbase.client.HTable;import org.apache.hadoop.hbase.client.Put Import org.apache.hadoop.hbase.client.Result;import org.apache.hadoop.hbase.client.ResultScanner;import org.apache.hadoop.hbase.client.Scan;import org.apache.hadoop.hbase.util.Bytes;public class DBhelper {public static Configuration config = new Configuration (); static {config.set ("hbase.zookeeper.property.clientPoint", "2181"); config.set ("hbase.zookeeper.quorum", "hbase") } / * * query value * parameters by criteria: table name, row, column cluster, column name * / public static void get (String tablename,String rowKey,String Family,String qualifier) throws Exception {HTable h=new HTable (config,tablename); System.out.println ("start getting-beep beep"); Get get=new Get (rowKey.getBytes ()); get.addColumn (Family.getBytes (), qualifier.getBytes ()); Result r=h.get (get) For (KeyValue kv:r.raw ()) {System.out.println ("the value you want to check is" + new String (kv.getValue ();}} / * * scan table * parameters: table name * / public static void scan (String tablename) throws Exception {HTable h=new HTable (config,tablename); System.out.println ("start scanning"); ResultScanner rs=h.getScanner (new Scan (tablename.getBytes () For (Result r:rs) {for (KeyValue kv:r.raw ()) {System.out.println (new String (kv.getRow ()) + "+ new String (kv.getFamily ()) +" + new String (kv.getQualifier ()) + "+ new String (kv.getValue ()) +" + kv.getTimestamp ());} System.out.println ("scan ends") } / * * add or modify data * parameters: table name, row, column cluster, column name, value * / public static void put (String tablename,String rowKey,String Family,String qualifier,String value) throws Exception {HTable h=new HTable (config,tablename); System.out.println ("--- adding -") Put put = new Put (Bytes.toBytes (rowKey)); put.add (Bytes.toBytes (Family), Bytes.toBytes (qualifier), Bytes.toBytes (value)); h.put (put); System.out.println ("--add complete -") } / * * delete table * parameters: table name * / public static void Delete (String tablename) throws Exception {HBaseAdmin h=new HBaseAdmin (config); if (h.tableExists (tablename)) {System.out.println ("deleting" + tablename); h.disableTable (tablename); h.deleteTable (tablename); System.out.println ("deleted successfully");} else {System.out.println ("stupid!" + tablename+ "does not exist");}} / * * create table * parameters: table name + column cluster * / public static void Create (String tablename,String Col) throws Exception {HBaseAdmin admin=new HBaseAdmin (config); if (admin.tableExists (tablename)) {System.out.println (tablename+ "already exists!") ;} else {System.out.println ("creating table:" + tablename); HTableDescriptor htd=new HTableDescriptor (tablename); System.out.println ("created successfully! adding column clusters:" + Col); htd.addFamily (new HColumnDescriptor (Col)); admin.createTable (htd); System.out.println ("created: / t Table name:" + tablename+ "\ t column Cluster:" + Col);}
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.