Java通过jdbc连接HIVE

一、连接

public static void main(String[] args) throws SQLException {
	   
	  try {
		Class.forName("org.apache.hive.jdbc.HiveDriver");
	} catch (ClassNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		System.exit(1);
	}
	  String uri = "jdbc:hive2://master:10000/default";
	  Connection con = DriverManager.getConnection(uri, "", "");
	  
	  String sql = "show tables";
	  System.out.println("Running " + sql +": ");
	  
	  Statement stmt = con.createStatement();
	  ResultSet res = stmt.executeQuery(sql);
	  System.out.println(res);
	  while(res.next()) {
		  System.out.println(res.getString(1));
		 
	  }
}
	  

二、pom.xml


  
      
     
        
        org.apache.maven.plugins  
        maven-compiler-plugin  
          
          1.8  
          1.8 
          UTF-8 
          
      
       
    
    
    
    
  
    
    org.apache.hadoop
    hadoop-common
    2.7.4





    com.google.guava
    guava
    25.0-jre



 
            jdk.tools
            jdk.tools
            1.8
            system
            ${JAVA_HOME}/lib/tools.jar
    
    
    

    org.apache.hadoop
    hadoop-common
    2.7.4

    

    org.apache.hive
    hive-exec
    1.2.2

    

    org.apache.hive
    hive-jdbc
    1.2.2

    

    org.apache.hive
    hive-metastore
    1.2.2

    

    org.apache.hive
    hive-service
    1.2.2

    

    org.apache.thrift
    libfb303
    0.9.3
    pom

    

    commons-logging
    commons-logging
    1.2

    

    org.slf4j
    slf4j-api
    1.8.0-beta2

    

  
  
  
  

 

你可能感兴趣的:(HIVE)