title: Connecting to remote Mapr Hive via JDBC
body: <p>This question is similar, but not the same, as <a href="https://stackoverflow.com/questions/11769477/hive-jdbc-getconnection-does-not-return">Hive JDBC getConnection does not return</a> . Yet this is about a remote connection. Also the metastore is present in the directory in which the hiveserver2 was started.</p>
  
  <p>We have a running mapr cluster on a remote machine. I would like to connect to Hive on this cluster using Java JDBC. </p>
  
  <p>Hence we started the hive server:</p>
  
  <p>/opt/mapr/hive/hive-0.11/bin/hiveserver2</p>
  
  <p>The output of the server process does not contain any error messages. It listens on port 10000 as reported by netstat.</p>
  
  <p>I try to connect to the server as described in <a href="https://cwiki.apache.org/confluence/display/Hive/HiveClient" rel="nofollow noreferrer">https://cwiki.apache.org/confluence/display/Hive/HiveClient</a>, thereby replacing localhost by the server name where the hiveserver2 is running:</p>
  
  <pre><code>Connection con = 
    DriverManager.getConnection("jdbc:hive://myserver.example.com:10000/default", "", "");
  </code></pre>
  
  <p>Yet the program hangs exactly at this statement. It does not seem to get a connection.</p>
  
  <p>Possibly I need to supply a username and password?</p>
  
  <p>Initially I had used the driver org.apache.hadoop.hive.jdbc.HiveDriver.</p>
  
  <p>Yet it seems like I should be using the driver org.apache.hive.jdbc.HiveDriver if the hive2 server is running. Now I am getting the following Exception:</p>
  
  <pre><code>Exception in thread "main" java.sql.SQLException: Could not establish connection to jdbc:hive2://myserver.example.com:10000/default: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null)
  at org.apache.hive.jdbc.HiveConnection.openSession(HiveConnection.java:246)
  at org.apache.hive.jdbc.HiveConnection.&lt;init&gt;(HiveConnection.java:132)
  at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
  at java.sql.DriverManager.getConnection(DriverManager.java:579)
  at java.sql.DriverManager.getConnection(DriverManager.java:221)
  at HiveJdbcClient.main(HiveJdbcClient.java:22)
  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:601)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  Caused by: org.apache.thrift.TApplicationException: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null)
  at org.apache.thrift.TApplicationException.read(TApplicationException.java:108)
  at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:71)
  at org.apache.hive.service.cli.thrift.TCLIService$Client.recv_OpenSession(TCLIService.java:144)
  at org.apache.hive.service.cli.thrift.TCLIService$Client.OpenSession(TCLIService.java:131)
  at org.apache.hive.jdbc.HiveConnection.openSession(HiveConnection.java:237)
  ... 10 more
  </code></pre>