【问题标题】:No suitable driver found for jdbc:presto找不到适合 jdbc:presto 的驱动程序
【发布时间】:2015-05-17 02:32:19
【问题描述】:

我想通过 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 吗?以及如何?

【问题讨论】:

  • 我认为您在应用程序运行时中缺少驱动程序负载。查看this question 的代码示例,因为我没有给你看。您基本上需要调用 Class.forName() 传递驱动程序名称(它应该在文档中可用)。
  • 谢谢,解决了一半的问题!

标签: maven jdbc presto


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    问题由两部分组成:

    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", "");

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2012-12-09
      • 2016-04-02
      • 2019-03-08
      • 2013-03-16
      • 2013-07-04
      • 2017-05-12
      • 2020-12-13
      • 1970-01-01
      相关资源
      最近更新 更多