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();
}
}