java - 通过 HADOOP 将数据插入 HIVE

标签 java hadoop hive hdfs

我在 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/

相关文章:

java - Java 中关闭数据库连接

java - 本地主机中的 Gae + Struts2 + Spring3 + Hibernate4 + MySQL 不会创建 http session ,并且数据存储始终为空

java - 列表与自身的 Hadoop 笛卡尔积

hadoop - Hive - 每小时窗口平均值

hadoop - 为什么分区可以在Hive表中媲美?

java - 如何在不中断 log4j2 的情况下在 Json 对象中记录异常堆栈跟踪

java - 如何在包上使用 NonNullByDefault

hadoop tmp 目录没有空间(设备 tmp 目录上没有剩余空间)

hadoop - 从哪里获取大数据管道的示例数据和查询?

mysql - hive中使用hadoop的基本sql查询问题