Advertisement
Guest User

Untitled

a guest
Jan 13th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.sql.SQLException;
  2. import java.sql.Connection;
  3. import java.sql.ResultSet;
  4. import java.sql.Statement;
  5. import java.sql.DriverManager;
  6.  
  7. public class HiveJdbcClient
  8. {
  9.     private static String driverName = "org.apache.hive.jdbc.HiveDriver";
  10.    
  11.     public static void main(String[] args) throws SQLException
  12.     {
  13.         try
  14.         {
  15.             Class.forName(driverName);
  16.         } catch (ClassNotFoundException e) {
  17.             e.printStackTrace();
  18.             System.exit(1);
  19.         }
  20.        
  21.         Connection con = DriverManager.getConnection("jdbc:hive2://srvg415:10000/default;password=;user=dwh");
  22.         Statement stmt = con.createStatement();
  23.        
  24.         String sql = "show tables in mr_metrics";
  25.         System.out.println("Running: " + sql);
  26.         ResultSet res = stmt.executeQuery(sql);
  27.         if (res.next()) {
  28.             System.out.println(res.getString(1));
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement