Hbase的SQL接口之Phoenix使用总结(1)
来源:互联网 发布:python中文编码问题 编辑:程序博客网 时间:2024/05/01 15:01
#最近在写操作HBase的接口,顺便研究了一下Phoenix,简单的介绍下Phoenix,Phoenix用Java实现,人们通过Phoenix,可以用自己所熟悉的SQL语言来操作HBase,当然它是开源的。
1.如何让HBase支持Phoenix?
将phoenix-1.1.jar复制到HBase集群每个节点的HBase文件夹下的lib目录,然后重启HBase
2.客户端怎么通过Phoenix访问或操作Hbase?
在你自己的Java项目下,引用phoenix-1.1-client.jar
下面给出使用Phoenix基本的代码:
public class HBaseUtility {static {try {Class.forName("com.salesforce.phoenix.jdbc.PhoenixDriver");} catch (ClassNotFoundException e) {throw new HBaseException(e);}}public static Connection getConnection() {String getDBConnectionString = "jdbc:phoenix:hadoop.master"; // 从配置文件中读取链接字符串try {Connection _Connection = DriverManager.getConnection(getDBConnectionString);return _Connection;} catch (SQLException e) {throw new HBaseException(e.getMessage(), e);}}}
public class HBaseHelper {static HBaseHelper _HBaseHelper = null;Connection _Connection = null;Statement _Statement = null;PreparedStatement _PreparedStatement = null;String _getExceptionInfoString = "";String _getDBConnectionString = "";private HBaseHelper() {}/* * Initialization */public static HBaseHelper getInstanceBaseHelper() {if (_HBaseHelper == null)synchronized (HBaseHelper.class) {if(_HBaseHelper==null)_HBaseHelper = new HBaseHelper();}return _HBaseHelper;}/* * Insert , Delete , Update */public Object ExcuteNonQuery(String sql) {int n = 0;try {_Connection =HBaseUtility.getConnection();_Statement = _Connection.createStatement();n = _Statement.executeUpdate(sql);_Connection.commit();} catch (Exception e) {Dispose();throw new HBaseException(e.getMessage(),e);} return n;}public Object ExcuteNonQuery(String sql, Object[] args) {int n = 0;try {_Connection =HBaseUtility.getConnection();_PreparedStatement = _Connection.prepareStatement(sql);for (int i = 0; i < args.length; i++)_PreparedStatement.setObject(i + 1, args[i]);n = _PreparedStatement.executeUpdate();_Connection.commit();} catch (SQLException e) {Dispose();throw new HBaseException(e.getMessage(),e);}return n;}/* * Query */public ResultSet ExecuteQuery(String sql) {ResultSet rsResultSet = null;try {_Connection =HBaseUtility.getConnection();_Statement = _Connection.createStatement();rsResultSet = _Statement.executeQuery(sql);} catch (Exception e) {Dispose();throw new HBaseException(e.getMessage(),e);} return rsResultSet;}public ResultSet ExceteQuery(String sql, Object[] args) {ResultSet rsResultSet = null;try {_Connection =HBaseUtility.getConnection();_PreparedStatement = _Connection.prepareStatement(sql);for (int i = 0; i < args.length; i++)_PreparedStatement.setObject(i + 1, args[i]);rsResultSet = _PreparedStatement.executeQuery();} catch (Exception e) {Dispose();throw new HBaseException(e.getMessage(),e);} return rsResultSet;}public void Dispose() {try {if (_Connection != null)_Connection.close();if (_Statement != null)_Statement.close();} catch (Exception e) {// TODO: handle exception_getExceptionInfoString = e.getMessage();}}}
以上是我写的一个基本的DBHelper类。因为自己不太会写Java代码,如果有不足之处,请各位指出。
关于Phoenix的详细信息,请参考:
1.http://blog.csdn.net/ricohzhanglong/article/details/8587493
2.https://github.com/forcedotcom/phoenix
待续。。。。
- Hbase的SQL接口之Phoenix使用总结(1)
- Hbase的SQL接口之Phoenix使用总结(1)
- Phoenix 使用sql查询hbase
- hbase SQL 框架phoenix使用
- Phoenix基本使用(HBase)
- SQL on HBase -- phoenix 之分页查询
- SQL on HBase -- phoenix 之分页查询
- 使用Apache Phoenix 实现 SQL 操作HBase
- Phoenix——HBase之上的SQL
- 使用Phoenix的JDBC接口
- HBase---Phoenix(SQL on HBase)
- Phoenix+HBase使用心得
- Phoenix+HBase使用心得
- 使用Phoenix连接Hbase
- hbase使用Phoenix
- 使用Phoenix通过sql语句更新操作hbase数据
- 使用Phoenix将SQL代码移植至HBase
- 使用Phoenix通过sql语句更新操作hbase数据
- Remove Duplicates from Sorted List
- shell for循环用法总结
- Python变量函数:函数名存在变量中
- 快速排序
- NameValueCollection集合
- Hbase的SQL接口之Phoenix使用总结(1)
- spoj1182
- 1019、最大乘积连续子串解析
- 睡眠关机脚本
- 日志操作实现思路
- C#用什么方法可以减少或不使用switch
- PKU ACM/ICPC竞赛队最近八年比赛成绩
- Android实现电话状态监控
- C++异常机制的实现方式和开销分析