1
votes

I have been trying to connect to my EMR cluster from java code to run a presto query. Until now I created a "maven project", and added "presto dependancy" in the "pom.xml". I have been referring this link for the program

https://gist.github.com/nagataka/2c2d9fa49b03e8556faf85345b43f59c

I have two questions:

1.) How do I connect to the EMR cluster with username and password like in the " conn = DriverManager.getConnection(DB_URL, USER, PASS);" used in the above reference. Because I use a ".ppk key" to validate the connection. I dunno how to give the key in this context.

2.) How do I run a simple "show tables;" query on Presto.

The following is my program:

package presto.presto_sample;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.*;

/**
 * Hello world!
 *
 */
public class App 
{
    static final String JDBC_DRIVER = "com.facebook.presto.jdbc.PrestoDriver";
    static final String DB_URL = "jdbc:presto://ec2-18-191-128-219.us-east-2.compute.amazonaws.com:8889/hive/default";
    public static void main( String[] args )
    {

        System.out.println( "Hello World!" );

    }
}
2

2 Answers

0
votes
Properties properties = new Properties();
properties.setProperty("user", "test");
properties.setProperty("password", "secret");
Connection connection = DriverManager.getConnection(url, properties);

i guess ppk can be another setProperty

see How to execute Presto query using Java API?

0
votes

You don't need to pass PPK key in the connection string properties. Your code may not be working because the firewall might be blocking you to connect to the server. To solve this you would have to add an inbound rule in the master security group to allow access to your IP. See this to add an inbound rule, Cannot connect/query from Presto on AWS EMR with Java JDBC

For checking out the tables: Set the String object "SQL" from the referenced program you are using and set its value to either "show tables from hive.default" (ex.) or if you have set catalog and schema name in connection property then just set it to "show tables".