使用jdbc访问presto的样例
2017-12-05 21:43 HeHongtao-key 阅读(9915) 评论(0) 编辑 收藏 举报1.先在pom.xml文件中添加依赖
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-jdbc</artifactId>
<version>0.100</version>
</dependency>
2.写一个最简单的类
package com.example.demo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class PrestoJDBC {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
Class.forName("com.facebook.presto.jdbc.PrestoDriver");
Connection connection = DriverManager.getConnection("jdbc:presto://jx-bd-hadoop100.zeus.lianjia.com:8091/hive/default","hive",null); ;
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("show tables");
while (rs.next()) {
System.out.println(rs.getString(1));
}
rs.close();
connection.close();
}
}