2

我想通过 JDBC 连接 Presto DB。

 String sql="Select * from mysql.infsci2711toturial.Person";
 String url="jdbc:presto://localhost:8080/catalog";//Under catalog folder, there is my mysql.properties file.

 Connection connection=null;
 try{
     connection=DriverManager.getConnection(url, "root", null);
     Statement stmt=connection.createStatement();
     ResultSet rs=stmt.executeQuery(sql);
     while(rs.next()){
         System.out.println(rs.getString(1));
     }
 }catch(SQLException ex){
     System.out.println(Arrays.toString(((URLClassLoader) ClassLoader.getSystemClassLoader()).getURLs()));
     ex.printStackTrace();

     System.out.println("wrong connection!");
 }

eclipse 中显示的问题是: 没有为 jdbc:presto://localhost:8080/catalog 找到合适的驱动程序 我试图将 presto-jdbc-0.93.jar 放在 WEB-INF/lib 下。但是不要解决这个问题。如何解决这个问题呢。我需要设置 Maven 吗?如何?

4

2 回答 2

2

添加 "Class.forName("com.facebook.presto.jdbc.PrestoDriver");" 并且 presto 需要 JDK 1.8。所以更新 JRE 到 1.8。

于 2015-03-14T21:07:52.407 回答
1

问题由两部分组成:

1- 找到合适的连接器。2-找到正确的连接网址。

就我而言,我需要连接到 AWS EMR 上的 Presto,以下对我有用:

  • 在您的 maven 依赖项中包含 presto-jdbc 驱动程序

    <!-- https://mvnrepository.com/artifact/com.facebook.presto/presto-jdbc -->
    <dependency>
        <groupId>com.facebook.presto</groupId>
        <artifactId>presto-jdbc</artifactId>
        <version>0.198</version>
    </dependency>
    
  • 在类路径中包含驱动程序类:

    final String JDBC_DRIVER = "com.facebook.presto.jdbc.PrestoDriver"; Class.forName(JDBC_DRIVER);

  • 使用正确的连接网址:

    final String DB_URL = "jdbc:presto://Your_ec2_ip_address:8889/hive/default";

  • 确保服务器上的8889端口是开放的

  • conn = DriverManager.getConnection(DB_URL, "hadoop", "");

希望这可以帮助。

于 2018-04-22T12:18:59.937 回答