在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 

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

不会再报

[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)
目录
相关文章
|
16天前
|
消息中间件 编译器 API
Windows窗口程序
Windows窗口程序
|
1月前
|
Windows
实现Windows程序的数据更新
实现Windows程序的数据更新
12 0
|
1月前
|
Windows
构建布局良好的Windows程序
构建布局良好的Windows程序
11 0
|
1月前
|
C# Windows
初识Windows程序
初识Windows程序
10 0
|
2月前
|
Java Linux Windows
windows实现自动部署jar包运行程序
windows实现自动部署jar包运行程序
43 0
|
4月前
|
移动开发
【实用】一组原创原生样式的基础控件、UI组件样式(偏向移动端H5页面的样式)
【实用】一组原创原生样式的基础控件、UI组件样式(偏向移动端H5页面的样式)
【实用】一组原创原生样式的基础控件、UI组件样式(偏向移动端H5页面的样式)
|
3月前
|
API Python Windows
python3应用windows api对后台程序窗口及桌面截图并保存的方法
python3应用windows api对后台程序窗口及桌面截图并保存的方法
94 1
|
1月前
|
数据可视化 数据库 C++
Qt 5.14.2揭秘高效开发:如何用VS2022快速部署Qt 5.14.2,打造无与伦比的Windows应用
Qt 5.14.2揭秘高效开发:如何用VS2022快速部署Qt 5.14.2,打造无与伦比的Windows应用
|
2月前
|
Windows
火山中文编程 -- 第一个windows程序
火山中文编程 -- 第一个windows程序
12 0