Phoenix操作hbase
来源:互联网 发布:淘宝月销量 编辑:程序博客网 时间:2024/05/16 12:13
1 shell命令操作hbase
可以把Phoenix和hbase的结合理解为类似MySQL的关系型数据库,这样比较便于理解使用。
Phoenix的crud和标准的SQL十分类似。
//创建表
create table IF NOT EXISTS test.Person (IDCardNum INTEGER not null primary key, Name varchar(20),Age INTEGER);
//插入数据
upsert into test.Person (IDCardNum,Name,Age) values (100,'Tom',12);
upsert into test.Person (IDCardNum,Name,Age) values (101,'Jerry',13);
upsert into test.Person (IDCardNum,Name,Age) values (102,'Mike',14);
//添加列
ALTER TABLE test.Person ADD sex varchar(10);
//更新数据
upsert into test.person (idcardnum,sex) values (100,'male');
upsert into test.person (idcardnum,sex) values (102,'male');
//删除数据
delete from test.Person where idcardnum=100;
//删除表
可以把Phoenix和hbase的结合理解为类似MySQL的关系型数据库,这样比较便于理解使用。
Phoenix的crud和标准的SQL十分类似。
//创建表
create table IF NOT EXISTS test.Person (IDCardNum INTEGER not null primary key, Name varchar(20),Age INTEGER);
//插入数据
upsert into test.Person (IDCardNum,Name,Age) values (100,'Tom',12);
upsert into test.Person (IDCardNum,Name,Age) values (101,'Jerry',13);
upsert into test.Person (IDCardNum,Name,Age) values (102,'Mike',14);
//添加列
ALTER TABLE test.Person ADD sex varchar(10);
//更新数据
upsert into test.person (idcardnum,sex) values (100,'male');
upsert into test.person (idcardnum,sex) values (102,'male');
//删除数据
delete from test.Person where idcardnum=100;
//删除表
drop table test.person;
2 使用Phoenix api来操作hbase
import java.sql.*;public class Test { static final String DRIVER = "org.apache.phoenix.jdbc.PhoenixDriver"; //类似于MySQL的驱动 static final String URL = "jdbc:phoenix:10.62.127.137:2181"; //连接Phoenix的地址,与MySQL类似 public static void main(String[] args) { String sql = "select * from test.person"; String sql1 = "upsert into test.Person (IDCardNum,Name,Age) values (102,'Mike',14)"; String sql2 = "upsert into test.person (idcardnum,sex) values (102,'male')"; Test test = new Test(); test.getConn(); try { test.HandPhoemix(sql2); test.select(sql); } catch (SQLException e) { e.printStackTrace(); } }/** * 建立连接 * 与MySQL类似 */ public Connection getConn() { Connection conn = null; try { Class.forName(DRIVER); if (conn == null) { conn = DriverManager.getConnection(URL); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return conn; }/** * 查询表 * 与MySQL类似 */ public void select(String sql) throws SQLException { Connection conn = getConn(); Statement stmt = conn.createStatement(); ResultSet result = stmt.executeQuery(sql); while (result.next()) { System.out.print("id: " + result.getInt("IDCARDNUM")); System.out.print(" name: " + result.getString("NAME")); System.out.print(" sex: " + result.getString("sex")); System.out.println(" age: " + result.getInt("age")); } result.close(); stmt.close(); conn.close(); }/** * 根据不同的sql语句进行插入、更新、删除表 * 与MySQL类似 */ public void HandPhoemix(String sql) throws SQLException { Connection conn = getConn(); Statement stmt = conn.createStatement(); stmt.executeUpdate(sql); conn.commit(); stmt.close(); conn.close(); }}
阅读全文
0 0
- PHOENIX操作HBASE
- Phoenix操作hbase
- 使用Apache Phoenix 实现 SQL 操作HBase
- Phoenix通过sql语句更新操作hbase
- 数据库操作:Jdbc,mysql,oracle,hbase,phoenix
- phoenix——提供hbase的sql操作的框架
- phoenix——提供hbase的sql操作的框架
- 使用用Phoenix的Java api操作HBase
- 使用Phoenix通过sql语句更新操作hbase数据
- 使用Phoenix通过sql语句更新操作hbase数据
- Phoenix 4.x +sqlline3.7操作hbase-0.98.6
- 安装SQuirrel SQL Client连接Phoenix操作HBase
- 使用 Phoenix 通过 sql 语句 更新操作 hbase 数据
- Phoenix安装使用及使用 SQuirrel客户端连接操作Hbase
- 使用Phoenix api操作hbase 报错java.lang.ClassNotFoundException: org.apache.phoenix.jdbc.PhoenixDriver
- phoenix access hbase
- Hadoop HBase Phoenix 版本
- Phoenix on HBase
- MySQL step by step 安装实战
- 利用py-faster-rcnn训练目标检测模型
- Oracle Spacial(空间数据库)SDO_GEOMETRY介绍
- 一些常用的JS方法
- dubbo高级篇-14 负载均衡算法
- Phoenix操作hbase
- Android6.0亮屏流程之Keyguard Window绘制
- css字体样式
- JS模拟的Map类实现方法
- MFC学习笔记2 Windows编程基础--MessageBox
- 17.开源项目--git将一个提交分解成多个提交
- JQuery UI Dialog 参数传递及事件交互技术
- zabbix基础
- 718[Medium]:Maximum Length of Repeated Subarray