使用 java 在配置单元中显示创建 table

show create table in hive using java

我正在尝试通过 JDBC 配置单元连接执行 show create table 语句。目的是获取包含hive数据的文件位置table.

我尝试了以下代码但出现了以下异常:

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)

请帮我解决这个问题。

使用下面的代码你可以获得table位置

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()