1.2 presto實現連接mongodb

1,首先檢查plugin文件,是否支持mongodb(版本:presto-server-0.221.tar.gz)

 

2,在etc/catalog下創建mongodb.properties

connector.name=mongodb

mongodb.seeds=192.168.227.3:27017

mongodb.schema-collection=admin

3,重啓presto

bin/launcher stop

bin/launcher start

4,測試連接

public class PrestoMongo {

    public static void main(String[] args) throws SQLException, ClassNotFoundException{

        //使用facebook驅動

        Class.forName("com.facebook.presto.jdbc.PrestoDriver");

        //url的填寫中使用 jdbc:presto://ip地址:端口號/system/runtime 其中system是指默認的catalog內所有的源數據連接,runtime是數據源中默認的schema,這樣寫後面的SQL語句

        //需要指定具體的數據源連接名和schema名,實現跨庫混合查詢

        Connection connection = DriverManager.getConnection("jdbc:presto://192.168.227.3:8001/mongodb/test","root",null);

        Statement stmt = connection.createStatement();

        ResultSet rs = stmt.executeQuery("show tables");

        while (rs.next()) {

            System.out.println(rs.getString(1));

        }

        rs.close();

        connection.close();

    }

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章