前言:
用到HBase的背景也是因为数据量到达了一定的量级,传统的关系型数据库存储处理有些乏力,故转为HBase这种扩展性更强、处理大数据更强的存储方式。
连接示例
try {
Connection con =
DriverManager.getConnection("jdbc:phoenix:hb-proxy-pub1,hb-proxy-pub2,hb-proxy-pub3", props);
Statement stmt = con.createStatement();
stmt.execute("drop table if exists test");
stmt.execute("create table test (mykey integer not null primary key, mycolumn varchar)");
stmt.execute("create index test_idx on test(mycolumn)");
stmt.executeUpdate("upsert into test values (1,'World!')");
stmt.executeUpdate("upsert into test values (2,'Hello')");
stmt.executeUpdate("upsert into test values (3,'World!')");
con.commit();
PreparedStatement statement = con.prepareStatement("select mykey from test where mycolumn='Hello'");
ResultSet rset = statement.executeQuery();
while (rset.next()) {
System.out.println(rset.getInt(1));
}
rset.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
连接超时
当检索大量数据的时候,可能会在等待一段时间后报错:
java.util.concurrent.ExecutionException: org.apache.phoenix.exception.PhoenixIOException: Failed after attempts=36, exceptions:
Caused by: org.apache.phoenix.exception.PhoenixIOException: Failed after attempts=36, exceptions:
Caused by: org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=36, exceptions:
Caused by: java.net.SocketTimeoutException