当前位置: 动力学知识库 > 问答 > 编程问答 >

java - 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;
分享给朋友:
您可能感兴趣的文章:
随机阅读: