Skip to content

Instantly share code, notes, and snippets.

@andypern
Created September 25, 2014 20:22
Show Gist options
  • Save andypern/b0aa02d446a8c5f413b6 to your computer and use it in GitHub Desktop.
Save andypern/b0aa02d446a8c5f413b6 to your computer and use it in GitHub Desktop.
// package drilljdbctest;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DrillJDBCTest {
private static final String SQL_STATEMENT = "SELECT * FROM `mfs`.`flat`.`./logs/2012/1/log.json`";
// Zookeeper node is running on this machine on the given port
private static final String CONNECTION_URL = "jdbc:drill:zk=ip-172-16-1-160:5181/drill/demorig-drillbits";
private static final String JDBC_DRIVER_NAME = "org.apache.drill.jdbc.Driver";
public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException {
System.out.println("\n=============================================");
System.out.println("DRILL JDBC Example");
System.out.println("Using Connection URL: " + CONNECTION_URL);
System.out.println("Running Query: " + SQL_STATEMENT);
Connection con = null;
Class.forName(JDBC_DRIVER_NAME);
con = DriverManager.getConnection(CONNECTION_URL);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(SQL_STATEMENT);
System.out.println("\n== Begin Query Results ======================");
// print the results to the console
while (rs.next()) {
System.out.println(rs.getString(1) + "|" + rs.getString(2));
}
System.out.println("== End Query Results =======================\n\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment