Home  >  Article  >  Backend Development  >  Python implementation example of connecting to phoenix

Python implementation example of connecting to phoenix

黄舟
黄舟Original
2017-10-03 05:47:022910browse

This article mainly introduces the method of connecting phoenix with Python, briefly explains the concept and functions of phoenix, and analyzes the related operating skills of Python connecting phoenix with specific examples. Friends in need can refer to it

The example in this article describes how to connect phoenix with Python. Share it with everyone for your reference, the details are as follows:

phoenix is ​​an open source project by saleforce.com and later donated to Apache. It is equivalent to a Java middleware that helps developers, such as using jdbc to access relational databases and NoSql database HBase. Phoenix can be seen as just a tool that replaces the syntax of HBase. Although you can use java or jdbc to connect to phoenix and then operate HBase, it cannot be used in OLTP in a production environment.

1. Solution

Here we connect through Jpype and JayDeBeApi

2. Process

Here I list the example code:


import jpype
import jaydebeapi
import os
phoenix_client_jar="/data/users/huser/phoenix/phoenix-4.3.0-client.jar"
args=='-Djava.class.path=%s'% phoenix_client_jar
jvm_path=jpype.getDefaultJVMPath()
jpype.startJVM(jvm_path,args)
conn=jaydebeapi.connect('org.apache.phoenix.jdbc.PhoenixDriver',['jdbc:phoenix:bj-g2hdp1,bj-g2hdp2,bj-g2hdp3:2181','',''],phoenix_clinent_jar)
curs=conn.cursor()
sql="select * from test"
count=curs.execute(sql)
results=curs.fetchall()
for r in results:
  print r

The above is the detailed content of Python implementation example of connecting to phoenix. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn