Created
August 21, 2020 08:55
-
-
Save wutiger555/b30ec07bc4615ffba51cd24f42561677 to your computer and use it in GitHub Desktop.
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.hive_example; | |
import java.sql.SQLException; | |
import java.sql.Connection; | |
import java.sql.ResultSet; | |
import java.sql.Statement; | |
import java.sql.DriverManager; | |
public class App { | |
private static String driverName = "org.apache.hive.jdbc.HiveDriver"; | |
public static void main(String[] args) throws SQLException { | |
try { | |
Class.forName(driverName); | |
} catch (ClassNotFoundException e) { | |
e.printStackTrace(); | |
System.exit(1); | |
} | |
Connection con = DriverManager | |
.getConnection("jdbc:hive2://[your uri]","",""); | |
Statement stmt = con.createStatement(); | |
String sql = "[your sql code]"; | |
stmt.execute(sql); | |
System.out.println("Running: " + sql); | |
ResultSet res = stmt.executeQuery(sql); | |
res = stmt.executeQuery(sql); | |
while (res.next()) { | |
System.out.println(res.getString(1)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment