我正在使用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或其他数据库语法不同。