2017-01-18 82 views
1

我嘗試以編程方式使用Apache Drill的JDBC驅動程序。如何以編程方式連接Hbase與Apache Drill的JDBC驅動程序

下面的代碼:

import java.sql.DriverManager 

object SearchHbaseWithHbase { 
    def main(args: Array[String]): Unit = { 
    Class.forName("org.apache.drill.jdbc.Driver") 
    val zkIp = "192.168.3.2:2181" 
    val connection = DriverManager.getConnection(s"jdbc:drill:zk=${zkIp};schema:hbase") 
    connection.setSchema("hbase") 

    println(connection.getSchema) 
    val st = connection.createStatement() 
    val rs = st.executeQuery("SELECT * FROM Label") 
    while (rs.next()){ 
     println(rs.getString(1)) 
    } 
    } 
} 

我已經設置了數據庫模式與類型:HBase的,像:

connection.setSchema("hbase") 

但它失敗,錯誤代碼:


Exception in thread "main" java.sql.SQLException: VALIDATION ERROR: From line 1, column 15 to line 1, column 19: Table 'Label' not found SQL Query null


Label表格正好在我的hbase中退出。 我可以找到我的數據,當我使用sqline像:

sqline -u jdbc:drill:zk.... 
use hbase; 
input :select * from Label; 

回答

1

我已經解決了這個問題。我迷惑了演練的架構和jdbc驅動架構...... 正確的代碼應該是這樣的:

object SearchHbaseWithHbase{ 
    def main(args: Array[String]): Unit = { 
    Class.forName("org.apache.drill.jdbc.Driver") 
    val zkIp = "192.168.3.2:2181" 
    val p = new java.util.Properties 
    p.setProperty("schema","hbase") 

// val connectionInfo = new ConnectionInfo 
    val url = s"jdbc:drill:zk=${zkIp}" 
    val connection = DriverManager.getConnection(url, p) 
// connection.setSchema("hbase") 
// println(connection.getSchema) 
    val st = connection.createStatement() 
    val rs = st.executeQuery("SELECT * FROM Label") 
    while (rs.next()){ 
     println(rs.getString(1)) 
    } 
    } 
} 
相關問題