Using Java for HBase client programming in Windows system and Eclipse IDE Integration environments

Source: Internet
Author: User
Tags root directory

This article takes HBase 0.90.2 as an example of how to use the Java language for HBase client programming in Windows systems, Eclipse IDE integration environments, including building tables, deleting tables, inserting records, deleting records, querying in various ways, and so on.

1. Preparatory work

1, download after the installation of JDK package (here is the use of jdk-6u10-rc2-bin-b32-windows-i586-p-12_sep_2008);

2, download Eclipse, extract to the local (here is the use of eclipse-java-helios-sr2-win32);

3, download HBase package, unzip the installation package to the local (here is the use of hbase-0.90.2).

2. Build the development environment

1. Run eclipse, create a new Java project "Hbaseclient", right-click the project root directory, select "Properties"-> "Java build Path"-> "Library"-> "Add External JARs ", add all jar packages under Hbase-0.90.2.jar, Hbase-0.90.2-tests.jar, and Lib subdirectories under the HBase root directory to the classpath of this project.

2, follow the actions in step 1 to add the HBase profile hbase-site.xml that you are connecting to the classpath of this project, as shown below as an example of a configuration file:

<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs:// hostname:9000/hbase</value>
</property>
<property>
<name> hbase.cluster.distributed</name>
<value>true</value>
</property>
< property>
<name>hbase.zookeeper.quorum</name>
<value>*.*.*.*, *.*.*.*, *.*.*.* </value>
</property>
<property skipindoc= "true" >
<name> hbase.defaults.for.version</name>
<value>0.90.2</value>
</property>
</configuration>

3, the following can be in the eclipse environment for hbase programming.

3. HBase Basic Operation code Example

3.1 Initialization configuration

privatestatic Configuration conf =null;
/**
 * Initialization configuration *
/static {
    conf = hbaseconfiguration.create ();
}

3.2 Creating a Table

/**
 * CREATE TABLE Operation
 * @throws ioexception
/publicvoid createtable (String tablename, string[] cfs) throws IOException {
    hbaseadmin admin =new hbaseadmin (conf);
if (admin.tableexists (tablename)) {
        System.out.println ("Table already exists!") ");
    }
else {
        htabledescriptor tabledesc =new htabledescriptor (tablename);
for (int i =0 i < cfs.length; i++) {
            tabledesc.addfamily (new Hcolumndescriptor (cfs[i));
        }
        Admin.createtable (TABLEDESC);
        SYSTEM.OUT.PRINTLN (the table was created successfully!) ");
    }
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.