Use Phoenix to connect HBase

Source: Internet
Author: User

To query hbase using SQL statements, you need to use the open source framework of Apache Phoenix.
Demo Environment: Phoenix 4.9.0-hbase-1.1 + Hbase 1.1.9 1 Local installation Phoenix

1.1 Download Phoenix

Download Phoenix from Apache (download link), from 4.8.0 to 4.10.0 each version, the local installed HBase version is 1.1.9, so choose the corresponding HBase is 1.1 version of the download. Here i download the 4.9.0 version, resource bundle apache-phoenix-4.9.0-hbase-1.1-bin.tar.gz

(Hbase 1.1.9 version download link)

1.2 Configuration

First, unzip the downloaded resource bundle to the local, Phoenix-4.9.0-hbase-1.1-client.jar and Phoenix-core-4.9.0-hbase-1.1.jar Two jar packages are copied to the HBase/lib folder. In addition, the configuration file for HBase is base-site.xml copied to the/bin folder in the Phoenix root directory. 1.3 Start

Start Hadoop First, then start HBase, and execute under the Phoenix folder:

bin/sqlline.py Master

Enter the Phoenix command line and execute

。 Tables

You can view all the data tables in all hbase.

1.4 Additions and deletions check and change operation
To create a table example:

CREATE TABLE person (ID varchar primary key, name varchar);

Insert Data Sample:

Upsert into the person values (' a ', ' Jone ');

The upsert here are both plugged in and updated, and the insert and update features in SQL are updated with the primary key updated.

To delete a data sample:

Delete from the person where id= ' 222 ';

Query Example:

select * from person;
2 integrating Phoenix in Java projects

Implementing Phoenix Operations in Java Projects Hbase,maven introducing Phoenix dependencies:

<dependency>
    <groupId>org.apache.phoenix</groupId>
    <artifactid>phoenix-core </artifactId>
    <version>4.9.0-HBase-1.1</version>
</dependency>

But the introduction of this package is not enough, but also need to introduce a dependent package Phoenix-4.9.0-hbase-1.1-client.jar, the dependency package can be found in the Phoenix file, can also download Phoenix source code, Self-compiling and importing, which can be hbase through Java JDBC Access operations.
The Java Test source code is as follows:

public static void Main (String args[]) {
    Connection Connection = null;
    Statement Statement = null;
    try {
        class.forname ("Org.apache.phoenix.jdbc.PhoenixDriver");
        Connection = Drivermanager.getconnection ("jdbc:phoenix:master:2181", "", "");
        statement = Connection.createstatement ();
        Statement.execute ("Upsert into Yinxiang_note values (3, ' note of Huhong ')");
        } catch (Exception e) {
            e.printstacktrace ();
        } finally {
            try {
                connection.close ();
                Statement.close ();
            } catch (Exception e) {
                e.printstacktrace ();}}}
    

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.