①先将phoenix的 core.jar包 和 phoenix的client.jar 包放到lib里。
②创建连接,过程和mysql类似
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
public
Connection GetConnection() {
Connection cc = null;
String driver =
"org.apache.phoenix.jdbc.PhoenixDriver"
;
// String url = "jdbc:phoenix:192.168.206.21:2181";
try
{
Class.forName(driver);
}
catch
(ClassNotFoundException e) {
e.printStackTrace();
}
if
(cc == null) {
try
{
cc = DriverManager.getConnection(url);
}
catch
(SQLException e) {
e.printStackTrace();
}
}
return
cc;
}
|
③执行sql语句,对用phoenix对hbase中表进行查询。
注:代码有点问题,我忘记释放链接了。注意加上。
④ 增,删,操作和查询类似,都是一条sql(略)。
⑤说明一下phoenix对hbase修改操作
OK 搞定了。