简体   繁体   中英

Connecting to remote HIVE server

I am trying to connect to a remote hive server. I have the following maven java code :

private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException {

       try {
           // Register driver and create driver instance
           Class.forName(driverName);
       } catch (ClassNotFoundException ex) {
           Logger.getLogger(ForHive.class.getName()).log(Level.SEVERE, null, ex);
       }

  // get connection
  System.out.println("before trying to connect");
  Connection con = DriverManager.getConnection("jdbc:hive://<hostip>:10000/", "hive", "");
  System.out.println("connected");

  // create statement
  Statement stmt = con.createStatement();

  // execute statement
  stmt.executeQuery("CREATE TABLE IF NOT EXISTS "
     +" consultant ( eid int, name String, "
     +" salary String, destignation String)"
     +" COMMENT ‘Employee details’"
     +" ROW FORMAT DELIMITED"
     +" FIELDS TERMINATED BY ‘\t’"
     +" LINES TERMINATED BY ‘\n’"
     +" STORED AS TEXTFILE;");

  System.out.println("Table employee created.");
  con.close();

}

But when I execute it gets stuck while trying to connect to the server and throws no exception either.

Try to use org.apache.hive.jdbc.HiveDriver driver. Connection string jdbc:hive2://<host>:10000/

Following ways are reasons for your problem.

1.Hive JDBC Class path is "org.apache.hive.jdbc.HiveDriver" and not "org.apache.hadoop.hive.jdbc.HiveDriver".

2.For hive server,

You can able to use like below.

Connection con = DriverManager.getConnection("jdbc:hive://:10000/default", "", "");

3.If you have using hiveserver2,

you have use below connection.

Connection con = DriverManager.getConnection("jdbc:hive2://:10000/default", "", "");

Above ways are surely helpful to you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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