title: Connect Hive through Java JDBC
body: <p>There is a question here <a href="https://stackoverflow.com/questions/25157273/connect-from-java-to-hive-using-jdbc">connect from java to Hive</a> but mine is <strong>different</strong> </p>
  
  <p>My hive running on machine1 and I need to pass some queries using Java server running at machine2. As I understand Hive has a JDBC interface for the purpose of receiving remote queries. I took the code from here - <a href="https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients" rel="nofollow noreferrer">HiveServer2 Clients</a></p>
  
  <p>I installed the dependencies written in the article:</p>
  
  <ol>
  <li>hive-jdbc*.jar   </li>
  <li>hive-service*.jar</li>
  <li>libfb303-0.9.0.jar   </li>
  <li>libthrift-0.9.0.jar</li>
  <li>log4j-1.2.16.jar</li>
  <li>slf4j-api-1.6.1.jar</li>
  <li>slf4j-log4j12-1.6.1.jar</li>
  <li>commons-logging-1.0.4.jar</li>
  </ol>
  
  <p>However I got <strong>java.lang.NoClassDefFoundError</strong> error at compile time
  <strong>Full Error:</strong></p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration
      at org.apache.hive.jdbc.HiveConnection.createBinaryTransport(HiveConnection.java:393)
      at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:187)
      at org.apache.hive.jdbc.HiveConnection.&lt;init&gt;(HiveConnection.java:163)
      at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
      at java.sql.DriverManager.getConnection(DriverManager.java:571)
      at java.sql.DriverManager.getConnection(DriverManager.java:215)
      at com.bidstalk.tools.RawLogsQuerySystem.HiveJdbcClient.main(HiveJdbcClient.java:25)
  </code></pre>
  
  <p>Another question at StackOverflow recommended to add Hadoop API dependencies in Maven - <a href="https://stackoverflow.com/questions/9089520/hadoop-maven-dependency-error">Hive Error</a></p>
  
  <p>I don't understand why do I need hadoop API for a client to connect with Hive. Shouldn't JDBC driver be agnostic of the underlying query system? I just need to pass some SQL query?</p>
  
  <p><strong><em>Edit:</em></strong> 
  I am using Cloudera(5.3.1), I think I need to add CDH dependencies. Cloudera instance is running hadoop 2.5.0 and HiveServer2</p>
  
  <p>But the servers are at machine 1. On machine the code should at least compile and I should have issues at runtime only!</p>