java phoenix 连接hbase


1 <dependency>
2     <groupId>org.apache.phoenix</groupId>
3     <artifactId>phoenix-core</artifactId>
4     <version>5.0.0-HBase-2.0</version>
5 </dependency>

除此之外还需要导入phoenix-5.0.0-HBase-2.0-client.jar

把以下文件拷贝到resources文件夹下

 1 public class Demo {  2     public static void main(String[] args) throws SQLException {  3         Connection connection = BaseDB.getConnection();  4 
 5         String sql = "select * from test";  6         PreparedStatement prepareStatement = connection.prepareStatement(sql);  7         ResultSet rs = prepareStatement.executeQuery();  8         while (rs.next()) {  9             System.out.println(rs.getInt(1)); 10             System.err.println(rs.getString(2)); 11  } 12 
13  } 14 } 15 public class BaseDB { 16     public static Connection getConnection() { 17         try { 18             Class.forName("org.apache.phoenix.jdbc.PhoenixDriver"); 19             return DriverManager.getConnection("jdbc:phoenix"); 20         } catch (Exception e) { 21  e.printStackTrace(); 22             return null; 23  } 24  } 25 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM