在windows下开发、调试hadoop 2程序

一、winutils的windows版本

      GitHub上,有牛人提供了winutils的windows的版本,项目地址是:https://github.com/srccodes/hadoop-common-2.2.0-bin

      直接下载此项目的zip包,下载后是文件名是hadoop-common-2.2.0-bin-master.zip,解压到一个目录

二、配置环境变量

    配置环境变量:
    HADOOP_HOME, 值是hadoop-common-2.2.0-bin-master.zip解压后的目录,如D:\Program\hadoop-common-2.2.0-bin-master

   

三、验证

   利用hive JDBC执行show tables 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
 
public class Demo {
     public final static String hiveJDBC = "jdbc:hive2://172.168.10.12:10000" ;
 
     public static void main(String[] args) throws Exception {
         Demo demo = new Demo();
         System.out.println( "测试hive程序" );
         demo.testHive();
     }
 
     public void testHive() throws Exception {
         Class.forName( "org.apache.hive.jdbc.HiveDriver" );
         //要带上这个用户名密码,就可以执行job任务,否则hive jdbc调用job会产生异常
         Connection conn = DriverManager.getConnection(hiveJDBC, "hive" , "hive" );
         Statement stmt = conn.createStatement();
         ResultSet rs = stmt.executeQuery( "show tables" );
         while (rs.next()) {
             for ( int i = 1 ; i < 2 ; i++) {
                 System.out.print(rs.getString(i) + " " );
             }
             System.out.println();
         }
         free(conn, stmt, rs);
     }
 
     public static synchronized void free(Connection conn, Statement st,
             ResultSet rs) {
         if (rs != null ) {
             try {
                 rs.close();
             } catch (SQLException e) {
                 e.printStackTrace();
             }
         }
         if (st != null ) {
             try {
                 st.close();
             } catch (SQLException e) {
                 e.printStackTrace();
             }
         }
         if (conn != null )
             try {
                 conn.close();
             } catch (SQLException e)

执行结果是:

测试hive程序
testtable
lzotable

不会再报

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[ 2014 - 07 - 02 09 : 57 : 05 , 651 ][ERROR][org.apache.hadoop.util.Shell: 336 ] - Failed to locate the winutils binary in the hadoop binary path
java.io.IOException: Could not locate executable null \bin\winutils.exe in the Hadoop binaries.
at org.apache.hadoop.util.Shell.getQualifiedBinPath(Shell.java: 318 )
at org.apache.hadoop.util.Shell.getWinUtilsPath(Shell.java: 333 )
at org.apache.hadoop.util.Shell.<clinit>(Shell.java: 326 )
at org.apache.hadoop.hive.conf.HiveConf$ConfVars.findHadoopBinary(HiveConf.java: 924 )
at org.apache.hadoop.hive.conf.HiveConf$ConfVars.<clinit>(HiveConf.java: 230 )
at org.apache.hive.jdbc.HiveConnection.isHttpTransportMode(HiveConnection.java: 304 )
at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java: 181 )
at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java: 164 )
at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java: 105 )
at java.sql.DriverManager.getConnection(DriverManager.java: 571 )
at java.sql.DriverManager.getConnection(DriverManager.java: 215 )
at impala.Demo.testHive(Demo.java: 27 )
at impala.Demo.main(Demo.java: 19 )
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值