JAVA连接presto
1、前言
java连接presto,操作hive,postgresql等数据库有两个版本
第一个是 io.prestosql.jdbc.PrestoDriver
版本,第二是 com.facebook.presto.jdbc.PrestoDriver
版本,两个版本所需要的jdbc驱动不同。
2、io.prestosql方式连接presto
2.1、io.prestosql驱动
<dependency>
<groupId>io.prestosql</groupId>
<artifactId>presto-jdbc</artifactId>
<version>345</version>
</dependency>
2.2、连接方式
/** io版
* 获取presto连接
* @param prestoUser presto
* @param prestoPassword presto
* @param prestoUrl jdbc:presto://127.0.0.1:8881/hive
* @return
*/
public static Connection prestoConnection(String prestoUser,String prestoPassword,String prestoUrl) {
try {
Connection conn = DriverManager.getConnection(prestoUrl, prestoUser, prestoPassword);
return conn;
} catch (Exception e) {
e.printStackTrace();
System.out.println("presto获取连接失败!");
return null;
}
}
3、facebook.presto方式连接presto
3.1、facebook.presto驱动
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-jdbc</artifactId>
<version>0.242.1</version>
</dependency>
3.2、连接方式
/**
* facebook版本
* 获取presto连接
* @param prestoUser presto
* @param prestoPassword presto
* @param prestoUrl jdbc:presto://127.0.0.1:8881/hive/ods
* @param prestoDriver com.facebook.presto.jdbc.PrestoDriver
* @return
*/
public static Connection prestoFacebookConnection(String prestoUser,String prestoPassword,String prestoUrl,String prestoDriver) {
try {
Class.forName(prestoDriver);
Connection conn = DriverManager.getConnection(prestoUrl, prestoUser, prestoPassword);
return conn;
} catch (Exception e) {
System.out.println("presto获取连接失败!");
return null;
}
}