Run Query to TreasureData via Presto JDBC driver with JAVA REPL
2 min readJan 22, 2020
When I want to check the behavior of Presto JDBC driver quickly, the preparation of Java environment like eclipse or etc is troublesome.
Since REPL has been provided as standard from Java 9 or later, I want to run a query to TreasureData using REPL via Presto JDBC.
give it a try!
- Check your java version
$ java -version
openjdk version “12.0.1” 2019–04–16
OpenJDK Runtime Environment (build 12.0.1+12)
OpenJDK 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)
2. Download Presto JDBC Driver from https://prestosql.io/docs/current/installation/jdbc.html
3. Go to the same dir with Presto JDBC
$ jshell --class-path presto-jdbc-328.jar
jshell>
4. Configure Presto JDBC Driver
jshell> import java.sql.DriverManager;
jshell> import java.util.Properties;
jshell> import java.sql.*;jshell> String url = "jdbc:presto://api-presto.treasuredata.com:443/td-presto/support";
url ==> "jdbc:presto://api-presto.treasuredata.com:443/td-presto/support"jshell> Properties properties = new Properties();
properties ==> {}jshell> properties.setProperty("user", "<TD APIKEY>");
$7 ==> nulljshell> properties.setProperty("password", "<dummy phrase>");
$8 ==> nulljshell> properties.setProperty("SSL", "true");
$9 ==> nulljshell> Connection connection = DriverManager.getConnection(url, properties);
connection ==> com.facebook.presto.jdbc.PrestoConnection@4b79ac84jshell> Statement stmt = connection.createStatement();
stmt ==> io.prestosql.jdbc.PrestoStatement@17bffc17
5. Run a Query
jshell> ResultSet rs = stmt.executeQuery("SELECT time, method, path from www_access limit 5");
rs ==> io.prestosql.jdbc.PrestoResultSet@4504d271
6. Conclusion
Easy to Run Presto job with Presto JDBC with REPL!
If you use OSS Presto, you can do it!