Presto-[6]-JDBC Driver 简介与Demo测试
来源:互联网 发布:漂移算法时间序列预测 编辑:程序博客网 时间:2024/06/08 10:34
官方文档
2.3. JDBC Driver
1-JDBC jar 或maven
Presto支持JDBC driver访问,下载 presto-jdbc-0.191.jar,添加到应用程序的 class path 中,同时也可以通过Maven中心仓库连接:
<dependency> <groupId>com.facebook.presto</groupId> <artifactId>presto-jdbc</artifactId> <version>0.191</version></dependency>
2-Connecting
支持以下URL形式:
jdbc:presto://host:portjdbc:presto://host:port/catalog(你的分类)jdbc:presto://host:port/catalog(你的分类)/schema(你的schema)
例如,用以下URL访问运行于 example.net
port 8080 的Presto的catalog
hive、
schema sales
:
jdbc:presto://example.net:8080/hive/sales
以上URL可以像下面的代码一样构建连接connection:
String url = "jdbc:presto://example.net:8080/hive/sales";Connection connection = DriverManager.getConnection(url, "test", null);
3-Connection Parameters
driver支持多项参数
- 作为URL的参数
以properties传给DriverManager
- 本地安装的presto没有设置密码,不用设置properties
- 若通过usr和password则必须设置SSL
以下两种形式等价:
// URL parametersString url = "jdbc:presto://example.net:8080/hive/sales";Properties properties = new Properties();properties.setProperty("user", "test");properties.setProperty("password", "secret");properties.setProperty("SSL", "true");Connection connection = DriverManager.getConnection(url, properties);// propertiesString url = "jdbc:presto://example.net:8080/hive/sales?user=test&password=secret&SSL=true";Connection connection = DriverManager.getConnection(url);
这些methods可能mixed,一些参数特定用在URL,一些特定用于properties,还有一些参数两种方法都可以使用
4-Parameter Reference
user
Username用于身份验证与授权
password
LDAP 身份验证密码
socksProxy
SOCKS proxy host、port,例如:localhost:1080
httpProxy
HTTP proxy host、port,例如:localhost:8888
SSL
用于HTTPS的connections
SSLKeyStorePath
Java KeyStore 文件location,Java KeyStore 包含certificate ,提供授权使用的key
SSLKeyStorePassword
KeyStore的password
SSLTrustStorePath
Java TrustStore文件的location,Java TrustStore用于HTTPS server授权
SSLTrustStorePassword
TrustStore. passwordKerberosRemoteServiceName
Presto coordinator Kerberos service name.该参数用于Kerberos 验证
KerberosPrincipal
principal 在Presto coordinator 验证时使用
KerberosUseCanonicalHostname
Use the canonical hostname of the Presto coordinator for the Kerberos service principal by first resolving the hostname to an IP address
and then doing a reverse DNS lookup for that IP address.
This is enabled by default.
KerberosConfigPath
Kerberos configuration file.KerberosKeytabPath
Kerberos keytab file.KerberosCredentialCachePath
Kerberos credential cache.5-Demo测试
启动hadoop、Presto、启动hive-meta和hive-server2 、运行MainApp 输出如下:
package com.learn; import java.sql.*;import java.util.Properties; public class MainApp { public static void main(String[] args) throws SQLException {// // properties// String url = "jdbc:presto://localhost:8080/hive/hive_test?user=hjw";// Connection connection = DriverManager.getConnection(url); // URL parameters String url = "jdbc:presto://localhost:8080/hive/hive_test"; //这里本地安装的presto没有设置密码,不用设置properties //若通过usr和password则必须设置SSL //Properties properties = new Properties(); //properties.setProperty("user", "root"); //properties.setProperty("password", "root"); //properties.setProperty("SSL", "true"); Connection connection = null; try { connection = DriverManager.getConnection(url, "hjw", null); Statement stmt = connection.createStatement(); String sql = "select * from student"; //executeQuery会返回结果的集合,否则返回空值 ResultSet rs = stmt.executeQuery(sql); System.out.println("学生id\t姓名"); while (rs.next()) { // 如果返回的是int类型可以用getInt() System.out.println(rs.getString(1) + "\t" + rs.getString(2)); } } catch (SQLException e) { e.printStackTrace(); } finally { connection.close(); } }}//查询结果//学生id 姓名//1001 zhangsan//1002 lisi
- Presto-[6]-JDBC Driver 简介与Demo测试
- facebook presto jdbc连接
- JDBC driver 与 JDK version
- Presto Benchmark Driver 的使用
- Presto简介<转>
- Presto简介相关
- JDBC与JDBC-1、简介
- org.gjt.mm.mysql.Driver与com.mysql.jdbc.Driver
- Mybatis与Eclipse--Exception getting JDBC Driver
- JDBC链接MySql数据库的测试Demo
- JDBC Driver
- JDBC DRIVER
- Presto安装与配置
- Presto查询性能测试记录
- jdbc简介与使用md
- webpack 安装与测试demo
- SQL Server 2000 Driver for JDBC安装与配置
- SQL Server 2000 Driver for JDBC安装与配置
- Python绘制双柱状图并显示数值
- 百度员工离职总结:资质平庸的人该怎么办?震惊了无数人!
- MAC
- SbulimeText3密匙
- 用shell脚本写的一个简单的计算器
- Presto-[6]-JDBC Driver 简介与Demo测试
- 每日总结
- 第十六周LeetCode
- (二)tomcat服务器配置虚拟主机
- Tip:MySQL数据库中关于数据表ID重置
- Linux 下分析Java程序CPU使用高的问题
- SCRAPY_part2_基础TIPS
- 阻塞queue系列之ArrayBlockingQueue
- Win7(64)+eclipse(64)+tomcat7(64)+jdk7(64)开发环境配置