You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by Sateesh Karuturi <sa...@gmail.com> on 2015/07/31 13:56:04 UTC

Getting error in creating a hive table via java

I would like to create a table in hive using Java. Using the following way
to do it:

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();
        String tableName = "sample";
        ResultSet res = stmt.executeQuery("create table access_log2
(cip string, csusername string, cscomputername string)");
        System.out.println("Table employee created.");
        con.close();
    }}

Exception in thread "main" java.sql.SQLException: Query failed
(#20150731_101653_00008_hv68j): Unknown type for column 'cip'

Re: Getting error in creating a hive table via java

Posted by Loïc Chanel <lo...@telecomnancy.net>.
The type String doesn't exist in SQL. I think you want to use VARCHAR
instead ;-)
Regards,


Loïc

Loïc CHANEL
Engineering student at TELECOM Nancy
Trainee at Worldline - Villeurbanne

2015-07-31 13:56 GMT+02:00 Sateesh Karuturi <sa...@gmail.com>:

> I would like to create a table in hive using Java. Using the following way
> to do it:
>
> 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();
>         String tableName = "sample";
>         ResultSet res = stmt.executeQuery("create table access_log2  (cip string, csusername string, cscomputername string)");
>         System.out.println("Table employee created.");
>         con.close();
>     }}
>
> Exception in thread "main" java.sql.SQLException: Query failed (#20150731_101653_00008_hv68j): Unknown type for column 'cip'
>
>