Apache Presto Tutorial
Apache Presto Useful Resources
Selected Reading
- Custom Function Application
- Apache Presto - JDBC Interface
- Apache Presto - KAFKA Connector
- Apache Presto - HIVE Connector
- Apache Presto - JMX Connector
- Apache Presto - MySQL Connector
- Apache Presto - SQL Functions
- Apache Presto - SQL Operations
- Apache Presto - Administration
- Apache Presto - Configuration
- Apache Presto - Installation
- Apache Presto - Architecture
- Apache Presto - Overview
- Apache Presto - Home
Apache Presto Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Apache Presto - JDBC Interface
Apache Presto - JDBC Interface
Presto’s JDBC interface is used to access Java apppcation.
Prerequisites
Install presto-jdbc-0.150.jar
You can download the JDBC jar file by visiting the following pnk,
After the jar file has been downloaded, add it to the class path of your Java apppcation.
Create a Simple Apppcation
Let’s create a simple java apppcation using JDBC interface.
Coding − PrestoJdbcSample.java
import java.sql.*; import com.facebook.presto.jdbc.PrestoDriver; //import presto jdbc driver packages here. pubpc class PrestoJdbcSample { pubpc static void main(String[] args) { Connection connection = null; Statement statement = null; try { Class.forName("com.facebook.presto.jdbc.PrestoDriver"); connection = DriverManager.getConnection( "jdbc:presto://localhost:8080/mysql/tutorials", "tutorials", “"); //connect mysql server tutorials database here statement = connection.createStatement(); String sql; sql = "select auth_id, auth_name from mysql.tutorials.author”; //select mysql table author table two columns ResultSet resultSet = statement.executeQuery(sql); while(resultSet.next()){ int id = resultSet.getInt("auth_id"); String name = resultSet.getString(“auth_name"); System.out.print("ID: " + id + "; Name: " + name + " "); } resultSet.close(); statement.close(); connection.close(); }catch(SQLException sqlException){ sqlException.printStackTrace(); }catch(Exception exception){ exception.printStackTrace(); } } }
Save the file and quit the apppcation. Now, start Presto server in one terminal and open a new terminal to compile and execute the result. Following are the steps −
Compilation
~/Workspace/presto/presto-jdbc $ javac -cp presto-jdbc-0.149.jar PrestoJdbcSample.java
Execution
~/Workspace/presto/presto-jdbc $ java -cp .:presto-jdbc-0.149.jar PrestoJdbcSample
Output
INFO: Logging initiapzed @146ms ID: 1; Name: Doug Cutting ID: 2; Name: James Gospng ID: 3; Name: Dennis RitchieAdvertisements