我在 redhat5 中使用 hadoop-1.0.4 和 hive-0.10.0。服务启动成功。我能够轻松地创建、删除、选择表,但我不知道如何插入数据。
例如,我有两个文本框,单击按钮时我想将数据存储在表 (userInfo) 中。我不知道如何在 userInfo(id,password) 中存储文本框值。
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/enggheads","", "");
Statement stmt = con.createStatement();
String tableName = "testHiveDriverTable";
stmt.executeQuery("drop table " + tableName);
ResultSet res = stmt.executeQuery("create table " + tableName + " (key int, value string)");
// show tables
String sql = "show tables '" + tableName + "'";
System.out.println("Running: " + sql);
res = stmt.executeQuery(sql);
if (res.next()) {
System.out.println(res.getString(1));
}
它是 Java,但我不知道如何插入两个字段值,因为 Hive 插入与 MySQL 或其他数据库语法不同。
最佳答案
像下面这样在 hive 中创建一个虚拟表
create table dummy(dummy string) location '/path';
以上路径将有一个包含数据 X
现在从 jdbc 驱动程序运行插入查询,如下所示。
insert into table tblname select forntendvalue1,frontendvalue2 from dual;
关于java - 通过 HADOOP 将数据插入 HIVE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16979815/