简体   繁体   中英

Insert data into HIVE over HADOOP

I am using hadoop-1.0.4 and hive-0.10.0 in redhat5 . Service start successfully. I am able to create, drop, select table easily but I don't know how to insert data.

For example I have two text box and on button click I want to store data in table (userInfo). I have no clue how to store textbox vaue in 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));
        }

It's Java, but I don't know how to insert two field value because Hive insertion is different than MySQL or other database syntax.

Create a dummy table in hive like below

create table dummy(dummy string) location '/path';

Above path will have a file which contains data X

Now run insert query from jdbc driver like below.

insert into table tblname select forntendvalue1,frontendvalue2 from dual;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM