Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 949
ruchi Avatar asked Mar 16 '26 23:03

ruchi


1 Answers

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;
like image 158
Balaswamy Vaddeman Avatar answered Mar 18 '26 12:03

Balaswamy Vaddeman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!