使用java在hive中显示create table

时间:2015-02-19 09:36:02

标签: java hadoop jdbc hive

我试图通过JDBC hive连接执行show create table语句。目的是获取包含hive表数据的文件的位置。

我尝试了以下代码,但遇到以下异常:

ResultSet rs = stmt.executeQuery(hiveTable);

    System.out.println("Resultset not null"+(rs != null));
    int i = 0;
    while(rs.next()){
        System.out.println(rs.getString(i));
        i++;
}

例外:

Exception in thread "main" java.sql.SQLException: Error while compiling statement: FAILED: ParseException line 1:4 cannot recognize input near 'show' '<EOF>' '<EOF>' in ddl statement
        at org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:120)
        at org.apache.hive.jdbc.Utils.verifySuccessWithInfo(Utils.java:108)
        at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:233)
        at org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:376)
        at com.capitalone.def.impl.TestClass.main(TestClass.java:33)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:212)

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

使用以下代码,您可以获得表格位置

HiveConf conf = new HiveConf();
conf.set(HiveConf.ConfVars.METASTOREURIS.varname, <metaStoreURI>);
HiveMetaStoreClient hiveMetaStoreClient = new HiveMetaStoreClient(conf);
Table tab = hiveMetaStoreClient.getTable(<db name>, <tab name>);
tab.getSd().getLocation()