title: How to access Hive using Java API in DSE
body: <p>I'm working on 5 node cluster with 2 cassandra,2 solr and 1 hadoop node on  DSE 4.0.3 , I'm trying to connect Hive thru java api.
  Below is the program I'm trying to execute</p>
  
  <pre><code>import java.sql.SQLException;
  import java.sql.Connection;
  import java.sql.ResultSet;
  import java.sql.Statement;
  import java.sql.DriverManager;
  
  public class HiveJdbcClient {
      private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
  
   /**
   * @param args
   * @throws SQLException
    */
   public static void main(String[] args) throws SQLException {
      try {
        Class.forName(driverName);
      } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      System.exit(1);
    }
    Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/default",  "", "");
    Statement stmt = con.createStatement();
    String tableName = "testHiveDriverTable";
    stmt.executeQuery("drop table " + tableName);
    ResultSet res = stmt.executeQuery("create table " + tableName + " (key int, value string)");
   // show tables
    String sql = "show tables '" + tableName + "'";
    System.out.println("Running: " + sql);
    res = stmt.executeQuery(sql);
    if (res.next()) {
      System.out.println(res.getString(1));
    }
    // describe table
    sql = "describe " + tableName;
    System.out.println("Running: " + sql);
    res = stmt.executeQuery(sql);
    while (res.next()) {
      System.out.println(res.getString(1) + "\t" + res.getString(2));
    }
  
    // load data into table
    // NOTE: filepath has to be local to the hive server
    // NOTE: /tmp/a.txt is a ctrl-A separated file with two fields per line
    String filepath = "/tmp/a.txt";
    sql = "load data local inpath '" + filepath + "' into table " + tableName;
    System.out.println("Running: " + sql);
    res = stmt.executeQuery(sql);
  
    // select * query
    sql = "select * from " + tableName;
    System.out.println("Running: " + sql);
    res = stmt.executeQuery(sql);
    while (res.next()) {
      System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));
    }
  
    // regular hive query
    sql = "select count(1) from " + tableName;
    System.out.println("Running: " + sql);
    res = stmt.executeQuery(sql);
    while (res.next()) {
      System.out.println(res.getString(1));
     }
    }
  }
  </code></pre>
  
  <p>But I'm getting  error when </p>
  
  <pre><code>Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/default", "", "");
  
  
  Exception in thread "main" java.lang.NoSuchMethodError: org.apache.thrift.protocol.TProtocol.getScheme()Ljava/lang/Class;
  at org.apache.hadoop.hive.service.ThriftHive$execute_args.write(ThriftHive.java:1076)
  at org.apache.thrift.TServiceClient.sendBase(TServiceClient.java:63)
  at org.apache.hadoop.hive.service.ThriftHive$Client.send_execute(ThriftHive.java:110)
  at org.apache.hadoop.hive.service.ThriftHive$Client.execute(ThriftHive.java:102)
  at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:192)
  at org.apache.hadoop.hive.jdbc.HiveStatement.execute(HiveStatement.java:132)
  at org.apache.hadoop.hive.jdbc.HiveConnection.configureConnection(HiveConnection.java:132)
  at org.apache.hadoop.hive.jdbc.HiveConnection.&lt;init&gt;(HiveConnection.java:122)
  at org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:106)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at example.create.HiveTable.main(HiveTable.java:22)
  </code></pre>
  
  <p>Note: I have started thrift server while running program
  $ dse hive --service hiveserver</p>
  
  <p>And Also I'm getting  when </p>
  
  <pre><code>Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "", "");
  
  Exception in thread "main" java.sql.SQLException: Invalid URL: jdbc:hive2://54.243.203.229:10000/default
  at org.apache.hadoop.hive.jdbc.HiveConnection.&lt;init&gt;(HiveConnection.java:86)
  at org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:106)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at example.create.HiveTable.main(HiveTable.java:22)
  </code></pre>
  
  <p>Note: I have started thrift server while running program
  $ dse hive --service hiveserver2</p>
  
  <p>Hite-site.xml is :</p>
  
  <pre><code>&lt;configuration&gt;
  &lt;!--Hive Execution Parameters --&gt;
    &lt;property&gt;
            &lt;name&gt;hive.exec.mode.local.auto&lt;/name&gt;
            &lt;value&gt;false&lt;/value&gt;
            &lt;description&gt;Let hive determine whether to run in local mode automatically&lt;/description&gt;
      &lt;/property&gt;
      &lt;property&gt;
            &lt;name&gt;hive.metastore.warehouse.dir&lt;/name&gt;
            &lt;value&gt;cfs:///user/hive/warehouse&lt;/value&gt;
            &lt;description&gt;location of default database for the warehouse&lt;/description&gt;
      &lt;/property&gt;
      &lt;property&gt;
             &lt;name&gt;hive.hwi.war.file&lt;/name&gt;
             &lt;value&gt;lib/hive-hwi.war&lt;/value&gt;
             &lt;description&gt;This sets the path to the HWI war file, relative to${HIVE_HOME}    &lt;/description&gt;
       &lt;/property&gt;
       &lt;property&gt;
              &lt;name&gt;hive.metastore.rawstore.impl&lt;/name&gt;
            &lt;value&gt;com.datastax.bdp.hadoop.hive.metastore.CassandraHiveMetaStore&lt;/value&gt;
              &lt;description&gt;Use the Apache Cassandra Hive RawStore implementation&lt;/description&gt;
        &lt;/property&gt;
        &lt;property&gt;
               &lt;name&gt;hadoop.bin.path&lt;/name&gt;
               &lt;value&gt;${dse.bin}/dse hadoop&lt;/value&gt;
         &lt;/property&gt;
         &lt;!-- Set this to true to enable auto-creation of Cassandra keyspaces as Hive Databases --&gt;
        &lt;property&gt;
              &lt;name&gt;cassandra.autoCreateHiveSchema&lt;/name&gt;
             &lt;value&gt;true&lt;/value&gt;
         &lt;/property&gt;
    &lt;/configuration&gt;
  </code></pre>
  
  <p>Can anyone please suggest something. where I'm wrong or missing anything.</p>