ubuntu16.04+hadoop2.7.2+hive1.2.1 server2通过jdbc连接

</pre><pre code_snippet_id="1748761" snippet_file_name="blog_20160706_2_3968882" name="code" class="html">package zg;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
 
public class HiveJdbcTest {
     
	  private static String driverName = "org.apache.hive.jdbc.HiveDriver";  
	  
	    public boolean run() {  
	  
	        try {  
	            Class.forName(driverName);  
	            Connection con = null;  
	            con = DriverManager.getConnection("jdbc:hive2://zhangge:10000/zhangge", "zhangge", "zhangge");  
	            //con = DriverManager.getConnection("jdbc:hive2://zhangge:10000/zhangge", "zhangge", "zhangge");
	            Statement stmt = con.createStatement();  
	            ResultSet res = null;  
	  
	            String sql = "select count(1) from t_mygril where age>19";  
	  
	            System.out.println("Running: " + sql);  
	            res = stmt.executeQuery(sql);  
	            System.out.println("ok");  
	            while (res.next()) {  
	                System.out.println(res.getString(1));  
	  
	            }  
	            return true;  
	        } catch (Exception e) {  
	            e.printStackTrace();  
	            System.out.println("error");  
	            return false;  
	        }  
	  
	    }  
	  
	    public static void main(String[] args) throws SQLException {  
	    	HiveJdbcTest hiveJdbcClient = new HiveJdbcTest();  
	        hiveJdbcClient.run();  
	    }  
}

用到的jar所有jar包http://download.csdn.net/detail/zhangge360/9568873

配置hive-site.xml

<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://zhangge:3306/hive?createDatabaseIfNotExist=true</value>
  <description>JDBC connect string for a JDBC metastore</description>
</property>
<property>
  <name>javax.jdo.option.ConnectionDriverName</name>
  <value>com.mysql.jdbc.Driver</value>
  <description>Driver class name for a JDBC metastore</description>
</property>
<property>
  <name>javax.jdo.option.ConnectionUserName</name>
  <value>zhangge</value>
  <description>username to use against metastore database</description>
</property>
<property>
  <name>javax.jdo.option.ConnectionPassword</name>
  <value>zhangge</value>
  <description>password to use against metastore database</description>
</property>
<property>
    <name>hive.hwi.listen.host</name>
    <value>zhangge</value>
</property>
<property>
    <name>hive.hwi.listen.port</name>
    <value>9999</value>
</property>
<property>
    <name>hive.hwi.war.file</name>
    <value>lib/hive-hwi-1.2.1.war</value>                                                                             
</property>
<property>
  <name>hive.server2.thrift.port</name>
  <value>10000</value>
</property>
<property>
  <name>hive.server2.thrift.bind.host</name>
  <value>zhangge</value>
</property>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值