ruchi
ruchi

Reputation: 996

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.

Upvotes: 3

Views: 7255

Answers (1)

Balaswamy Vaddeman
Balaswamy Vaddeman

Reputation: 8540

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;

Upvotes: 1

Related Questions