依赖
com.facebook.presto
presto-jdbc
0.245
1 maven与presto集成代码
import java.sql.*;
import java.util.*;
public class prestoQuery {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
Class.forName("com.facebook.presto.jdbc.PrestoDriver");
Connection connection = DriverManager.getConnection("jdbc:presto://hadoop102:8090/hive/test","hive",null); ;
Statement stmt = connection.createStatement();
String sql = "select * from motor limit 10000";
//获取开始时间
long startTime = System.currentTimeMillis();
List
2 SpringBoot集成Presto
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.sql.*;
import java.util.*;
@RestController
@RequestMapping("/presto")
public class PrestoQueryController {
//将Connection、Statement 作为全局变量写在方法体外,避免每调用一次方法进行一次连接,节省资源
// Class.forName("com.facebook.presto.jdbc.PrestoDriver");
Connection connection = DriverManager.getConnection("jdbc:presto://hadoop102:8090/hive/test","root",null);
Statement stmt = connection.createStatement();
//全局变量后 写构造器
public PrestoQueryController() throws SQLException {
}
@RequestMapping("/queryDatabases")
public List DataBasesList() throws Exception {
String sql = "show schemas from hive"; //展示hive的所有库
ResultSet rs = stmt.executeQuery(sql);
List list = new ArrayList<>(); //存放结果(hive的所有库)
// 库遍历
ResultSetMetaData md = rs.getMetaData();
int columnCount = md.getColumnCount();
while (rs.next()) {
List rowData = new ArrayList<>();
for (int i = 1; i <= columnCount; i++) {
rowData.add(rs.getObject(i));
}
list.add(rowData);
}
return list;
}
//http://localhost:8088/presto/queryDatabases
@RequestMapping("/queryTable")
public List
3 测试