HIVE JDBC接続の詳細
package org.conan.myhadoop.mr;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class HiveJDBCConnection {
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
// Hive 0.11.0 org.apache.hive.jdbc.HiveDriver
private static String url = "jdbc:hive://localhost:10000/default";
// Hive 0.11.0 jdbc:hive2://localhost:10000/default
private static String userName = "";
private static String passWord = "";
public static void main(String[] args) {
try {
Class.forName(driverName);
Connection con = DriverManager.getConnection("url", "userName",
"passWord");
Statement stmt = con.createStatement();
//
String tableName = "jdbc_table";
String sql = "drop table if exists " + tableName;
stmt.execute(sql);
//
sql = "create table"
+ tableName
+ " (key string,value string) row format delimited fields terminated by ',' stored as textfile ";
stmt.execute(sql);
//
String Path="/home/hive_1.txt";
sql ="load data local inpath '"+Path+"' into table "+tableName;
stmt.execute(sql);
//
sql ="select * from "+tableName;
ResultSet res = stmt.executeQuery(sql);
while(res.next()){
System.out.println(res.getString(1)+"\t"+res.getString(1));
}
} catch (ClassNotFoundException e) {
System.out.println(" ");
e.printStackTrace();
} catch (SQLException e) {
System.out.println(" Hive ");
e.printStackTrace();
}
}
}
上はJavaでHiveServerに接続していますが、HiveServer自体には多くの問題(例えば、セキュリティ、同時性など)があります.これらの問題に対して、Hive 0.11.0バージョンでは、HiveServer 2という新しいサービスが提供されています.これは、HiveServerに存在するセキュリティ、同時性などの問題を解決するのに役立ちます.
上のuserNameとpassWordはhiveメタデータmysqlのユーザー名とパスワードです
Use Cases: Hive CLI versus Beeline
The following section focuses on the common uses of Hive CLI/HiveServer1 and how you can migrate to Beeline/HiveServer2 in each case.
http://blog.cloudera.com/blog/2014/02/migrating-from-hive-cli-to-beeline-a-primer/?utm_source=tuicool&utm_medium=referral
参考記事:
http://www.iteblog.com/archives/846