pom.xml配置
<dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-jdbc</artifactId> <version>0.13.1</version> </dependency>
测试例程
1 import org.junit.Test; 2 3 import java.sql.SQLException; 4 import java.sql.Connection; 5 import java.sql.ResultSet; 6 import java.sql.Statement; 7 import java.sql.DriverManager; 8 9 /** 10 * Created by Administrator on 2017/7/29. 11 */ 12 public class TestHiveJDBC { 13 14 private static String driverName = "org.apache.hive.jdbc.HiveDriver"; 15 16 @Test 17 public void TestConnection() throws SQLException { 18 try { 19 Class.forName(driverName); 20 } catch (ClassNotFoundException e) { 21 // TODO Auto-generated catch block 22 e.printStackTrace(); 23 System.exit(1); 24 } 25 Connection con = null; 26 Statement stmt = null; 27 try{ 28 con = DriverManager.getConnection("jdbc:hive2://hadoop-senior.jason.com:10000/db_hive", "jason", "abc123"); 29 stmt = con.createStatement(); 30 // show tables 31 String sql = "select * from bf_log_20170712"; 32 ResultSet res = stmt.executeQuery(sql); 33 while(res.next()){ 34 System.out.println("ip: "+res.getString(1)+" name: "+res.getString(2)+" website: "+res.getString(3)); 35 } 36 }catch(SQLException e){ 37 e.printStackTrace(); 38 }finally { 39 stmt.close(); 40 con.close(); 41 } 42 } 43 44 }