- public class HiveJdbcClient2 {
- private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
- /**
- * @param args
- * @throws SQLException
- */
- public static void main(String[] args) throws SQLException {
- System.setProperty("hadoop.home.dir", "D:/hadoop-2.4.0");
- BasicConfigurator.configure();
- try {
- Class.forName(driverName);
- } catch(ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- System.exit(1);
- }
- Connection con = DriverManager.getConnection("jdbc:hive://127.0.0.1:10000/defalt", "", "");
- Statement stmt = con.createStatement();
- //stmt.executeQuery("drop table test");
- stmt.executeQuery("create table if not exists test(amount DOUBLE, st_name string) " + "ROW FORMAT DELIMITED " + "FIELDS TERMINATED BY '\t' " + "STORED AS TEXTFILE");
- //stmt.executeQuery("load data inpath '/user/hive_data/test_data.txt' into table gas");
- long st = System.currentTimeMillis();
- ResultSet res = stmt.executeQuery("select st_name,sum(amount) c from test group by st_name sort by c");
- int i = 0;
- while (res.next()) {
- i++;
- System.out.println(res.getString(1) + " - " + res.getString(2));
- }
- long en = System.currentTimeMillis();
- System.out.println("总耗时:" + (en - st) + ",记录总数:" + i);
- }
- }
来源: http://lib.csdn.net/snippet/hive/49914