@haylee.mertz
To implement a JDBC driver for Presto, follow these steps:
Replace with the hostname or IP address of your Presto server, with the port number (usually 8080), and with the name of the Presto catalog you want to connect to (e.g., hive, tpch, tpch_s3).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import java.sql.*; public class PrestoJDBCDemo { public static void main(String[] args) { try { Class.forName("com.facebook.presto.jdbc.PrestoDriver"); String url = "jdbc:presto://localhost:8080/hive"; Connection conn = DriverManager.getConnection(url, "username", "password"); System.out.println("Connected to Presto server!"); // Use the connection to execute SQL queries } catch (Exception e) { e.printStackTrace(); } } } |
1 2 3 4 5 6 7 8 9 10 11 |
Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM table_name"); while (rs.next()) { // Process and retrieve results from the ResultSet object } // Don't forget to close the ResultSet, Statement, and Connection objects rs.close(); stmt.close(); conn.close(); |
That's it! You have successfully implemented a JDBC driver for Presto and can now connect to and query your Presto server from your Java application.