Pom.xml Configuration
<Dependency> <groupId>Org.apache.hive</groupId> <Artifactid>Hive-jdbc</Artifactid> <version>0.13.1</version> </Dependency>
Test routines
1 Importorg.junit.Test;2 3 Importjava.sql.SQLException;4 Importjava.sql.Connection;5 ImportJava.sql.ResultSet;6 Importjava.sql.Statement;7 ImportJava.sql.DriverManager;8 9 /**Ten * Created by Administrator on 2017/7/29. One */ A Public classTESTHIVEJDBC { - - Private StaticString drivername = "Org.apache.hive.jdbc.HiveDriver"; the - @Test - Public voidTestconnection ()throwsSQLException { - Try { + Class.forName (drivername); -}Catch(ClassNotFoundException e) { + //TODO auto-generated Catch block A e.printstacktrace (); atSystem.exit (1); - } -Connection con =NULL; -Statement stmt =NULL; - Try{ -con = drivermanager.getconnection ("Jdbc:hive2://hadoop-senior.jason.com:10000/db_hive", "Jason", "abc123"); instmt =con.createstatement (); - //Show Tables toString sql = "SELECT * FROM bf_log_20170712"; +ResultSet res =stmt.executequery (SQL); - while(Res.next ()) { theSystem.out.println ("IP:" +res.getstring (1) + "Name:" +res.getstring (2) + "website:" +res.getstring (3)); * } $}Catch(SQLException e) {Panax Notoginseng e.printstacktrace (); -}finally { the stmt.close (); + con.close (); A } the } + -}
Hive JDBC Operation Example