Hive-jdbc 드라이버

1258 단어 Hive

 
 
 
1. hiveserver2 , 10000
		$>hive --service hiveserver2 &

	2. beeline hiveserver2
		$>beeline											// beeline ( hive --service beeline)
		$beeline>!help										// 
		$beeline>!quit										// 
		$beeline>!connect jdbc:hive2://localhost:10000/mydb2// hibve 
		$beeline>show databases ;
		$beeline>use mydb2 ;
		$beeline>show tables;	

jdbc 방식으로 원격 데이터 창고에 접근하기
의존하다
                
					org.apache.hive
					hive-jdbc
					2.1.0
				

 
 
코드:

		/**
		 *  jdbc hive , hiveserver2 。
		 */
		public class App {
			public static void main(String[] args) throws  Exception {
				Class.forName("org.apache.hive.jdbc.HiveDriver");
				Connection conn = DriverManager.getConnection("jdbc:hive2://192.168.136.128:10000/mydb2");
				Statement st = conn.createStatement();
				ResultSet rs = st.executeQuery("select id , name ,age from t");
				while(rs.next()){
					System.out.println(rs.getInt(1) + "," + rs.getString(2)) ;
				}
				rs.close();
				st.close();
				conn.close();
			}
		}

좋은 웹페이지 즐겨찾기