人民币被仿制成冥币,ca947航班,澳门博彩中介
今天看看怎样在 python 中使用 phoenixdb 来操作 hbase
安装 phoenixdb 库
pip install phoenixdb
例子
首先启动 queryserver 服务
cd apache-phoenix-4.14.1-hbase-1.4-bin/bin ./queryserver.py
然后使用下面代码来建立连接、创建/删除并查询表。代码比较简单,和我们通常查询关系型数据库比较类似,这里就不多说了哈。
import phoenixdb import phoenixdb.cursor url = 'http://localhost:8765/' conn = phoenixdb.connect(url, autocommit=true) cursor = conn.cursor() # cursor.execute("drop table users") cursor.execute("create table users (id integer primary key, username varchar, password varchar)") cursor.execute("upsert into users values (?, ?, ?)", (1, 'admin', 'letmein')) cursor.execute("upsert into users values (?, ?, ?)", (2, 'kongxx', 'letmein')) cursor.execute("select * from users") print cursor.fetchall() cursor = conn.cursor(cursor_factory=phoenixdb.cursor.dictcursor) cursor.execute("select * from users where id=1") user = cursor.fetchone() print user['username'] print user['password']
最后运行这个程序看一下效果吧。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
新手学习Python2和Python3中print不同的用法
Python基于os.environ从windows获取环境变量
网友评论