繁体   English   中英

如何使用java在hive中创建表?

[英]how to create a table in hive using java?

我想使用Java在hive中创建一个表。 使用以下方法执行此操作:

public class HiveCreateTable {
    private static String driverName = "com.facebook.presto.jdbc.PrestoDriver";
    public static void main(String[] args) throws SQLException {
        // Register driver and create driver instance
        try {
            Class.forName(driverName);
        } 
        catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("haiiiiii");
        Connection con = DriverManager.getConnection("jdbc:presto://192.168.1.119:8082/default", "hadoop", "password");
        con.setCatalog("hive");
        con.setSchema("log");
        Statement stmt = con.createStatement();
        ResultSet res = stmt.executeQuery("create table access_log2  (cip string, csusername string, cscomputername string)");
        System.out.println("Table created.");
        con.close();
    }
}

错误:

线程“main”java.sql.SQLException中的异常:查询失败(#20150731_101653_00008_hv68j):列'cip'的未知类型

在上面的代码中,您使用的是Presto JDBC驱动程序,而不是Hive。 我不确定你想要实现什么,但Presto支持以下数据类型,其中String不是一个:

https://prestodb.io/docs/current/language/types.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM