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

我想使用
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();
    }
}

错误:

Exception in thread “main” java.sql.SQLException: Query failed
(#20150731_101653_00008_hv68j): Unknown type for column ‘cip’

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

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

点赞