2

I want to connect Presto DB by JDBC.

 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!");
 }

The problem show in eclipse is that: No suitable driver found for jdbc:presto://localhost:8080/catalog I have tried to put presto-jdbc-0.93.jar under WEB-INF/lib. But don't solve this problem. How to solve this problem. Do I need set Maven? and how?

Damien Carol
  • 1,164
  • 1
  • 11
  • 21
Hao Wu
  • 143
  • 1
  • 11
  • I think you're missing the driver load within your application runtime. Check [this question](http://stackoverflow.com/q/6164950/3127111) for a code example, as I have none to show you. You basically need to call `Class.forName()` passing the driver name (it should be available in the docs). – watery Mar 14 '15 at 19:57
  • Thanks, it solves half of problem! – Hao Wu Mar 14 '15 at 21:07
  • Follow this tutorial https://www.tutorialspoint.com/apache_presto/apache_presto_jdbc_interface.htm – newstackoverflowuser5555 Feb 23 '17 at 14:00

2 Answers2

2

Add "Class.forName("com.facebook.presto.jdbc.PrestoDriver");" And presto require JDK 1.8. So update JRE to 1.8.

Hao Wu
  • 143
  • 1
  • 11
1

The problem consists of two parts:

1- Finding the right connetor. 2- Finding the right connection url.

In my case, I needed to connect to Presto on AWS EMR and the following worked for me:

  • Include presto-jdbc driver in your maven dependancies

    <!-- https://mvnrepository.com/artifact/com.facebook.presto/presto-jdbc -->
    <dependency>
        <groupId>com.facebook.presto</groupId>
        <artifactId>presto-jdbc</artifactId>
        <version>0.198</version>
    </dependency>
    
  • Include the driver class in your classpath:

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

  • Use the right connection url:

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

  • Make sure that the port 8889 is open on the server

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

Hope this helps.

Abdulhafeth Sartawi
  • 1,086
  • 1
  • 11
  • 20