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