没有找到适合 jdbc:presto 的驱动程序



我想通过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!");
 }

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

添加"Class.forName("com.facebook.presto.jdbc.PrestoDriver");"并且需要 JDK 1.8。因此,请将 JRE 更新到 1.8。

该问题由两部分组成:

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

就我而言,我需要连接到 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", "");

希望这有帮助。