Created
December 15, 2014 18:16
Sample JDBC Program for connecting to HDP 2.2 Hive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.spnotes.hive; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.ResultSet; | |
/** | |
* Hello world! | |
* | |
*/ | |
public class App | |
{ | |
private static String driverName = "org.apache.hive.jdbc.HiveDriver"; | |
public static void main( String[] args )throws Exception{ | |
try { | |
Class.forName(driverName); | |
Connection connection = null; | |
System.out.println("Before getting connection"); | |
connection= DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "root", "hadoop"); | |
System.out.println("After getting connection " + connection); | |
ResultSet resultSet = connection.createStatement().executeQuery("select * from default.employee"); | |
while (resultSet.next()) { | |
System.out.println(resultSet.getString(1) + " " + resultSet.getString(2)); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
System.exit(1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment