Using JDBC API with Apache Phoenix
You can create and interact with Apache HBase tables using Phoenix DDL/DML statements through its standard JDBC API. Apache Phoenix JDBC driver can be easily embedded in any application that supports JDBC.
Apache Phoenix enables you to use the standard JDBC API to create and access Apache HBase tables. You can use JDBC APIs with Apache Phoenix instead of native Apache HBase client APIs to create tables, insert, and query data.
Apache Phoenix tables have a 1:1 relationship with Apache HBase tables. You can choose to
create a new table using an Apache Phoenix DDL statement such as CREATE
TABLE
, or create a view on an existing Apache HBase table using the
VIEW
statement.
- A thick driver communicates directly with Apache HBase. The thick driver, therefore, needs access to all the nodes in the Apache HBase cluster.
- A thin driver communicates with Apache HBase through Phoenix Query Server (PQS) and requires access only to PQS. Use the thin driver to connect to PQS through Apache Knox or connect to PQS directly.
In an operational database Data Hub cluster, Data Lake (SDX cluster) provides security dependencies such as Apache Knox. Your JDBC URL string would depend on whether you want to connect directly or through Apache Knox. Before you try connecting to Apache Phoenix, check if you are in the list of allowed users in Apache Ranger allowed to access Apache Phoenix and Apache HBase.
Based on whether you want to use the thick or thin driver, you need the JAR files for the Apache HBase client, the Apache Phoenix client, and the PQS client.
For the thick driver, you need:
hbase-client-[***VERSION***].jar
hbase-site.xml
For the thin driver, you need:
phoenix-queryserver-client-[***VERSION***].jar
You can get these JAR files from the following locations:
- Go to /opt/cloudera/parcels/CDH/lib/phoenix/ on an operational
database cluster node with the phoenix-gateway role
or
- Download the JAR files from the Cloudera Repository
When using the thin driver, your applications interact with the Phoenix Query Server using the Avatica API and Google Protocol Buffers serialization format.
JDBC driver location
Use the /opt/cloudera/parcels/CDH/lib/phoenix/[***PHOENIX VERSION***].jar file present in your deployment location. For example, /opt/cloudera/parcels/CDH/lib/phoenix/phoenix-5.0.0.7.2.0.0-128-client.jar
URL syntax for the thick JDBC driver
jdbc:phoenix:[***zookeeper_quorum***]:[***zookeeper_port***]:[***zookeeper_hbase_path***]
The
zookeeper_quorum
and zookeeper_port
parameters are
optional if you have added the operational database Apache HBase cluster's current
hbase-site.xml to the application classpath.Apart from the JDBC driver, the following drivers are supported:
- ODBC driver
- Python driver for Phoenix