AnsweredAssumed Answered

Unable to connect to Hive table

Question asked by SanjeevSukumaran on Jul 12, 2016
Latest reply on Jul 15, 2016 by snayeem


Below is my java program to display the contents of table test7:

 

package drill2;
import java.sql.*;
public class Extract2 {


   // private static String connectionString = "jdbc:hive2://10.10.80.231:21050/;auth=noSasl";
    private static String sql;
//   private static Connection con;
    //private static ResultSet resultSet;
// private static Statement sqlStatement
    private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
    //private static String USER="hive";
    //private static String PASS="mapr";
    private static String JDBC_DRIVER="jdbc:hive2://chu4l5ap67:10000/;auth=noSasl";
   
    public static void main(String[] args) throws SQLException {
  try {
  Class.forName(driverName);
  } catch (ClassNotFoundException e) {
  e.printStackTrace();
  System.exit(1);
  }
  try
  {
  Connection con = DriverManager.getConnection(JDBC_DRIVER);
  Statement stmt = con.createStatement();
  sql = "SELECT * from test7";
       ResultSet rs = stmt.executeQuery(sql);
       while(rs.next())
          {
                  System.out.println("Result set "+rs.getString(1));
          }
          con.close();
  }

  catch(SQLException sqle)
  {
          System.out.println("Got sql exception");
          sqle.printStackTrace();
  }
  catch(Exception e)
  {
          System.out.println("Got exception");
          e.printStackTrace();
  }
}
}

 

Below are the contents of my pom.xml file:

 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>drill1</groupId>
  <artifactId>drill2</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <dependencies>
  <dependency>
  <groupId>org.apache.drill.exec</groupId>
  <artifactId>drill-jdbc</artifactId>
  <version>1.6.0</version>
  </dependency>
  <dependency>
  <groupId>org.apache.hive</groupId>
  <artifactId>hive-jdbc</artifactId>
  <version>1.2.1</version>
  </dependency>
  </dependencies>

  <dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-jdbc</artifactId>
    <version>1.2.1</version>
</dependency>
</project>

 

But when i run this program iam getting the following error:

 

java.lang.ClassNotFoundException: org.apache.hadoop.hive.jdbc.HiveDriver
  at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:190)
  at drill2.Extract2.main(Extract2.java:18)

 

Even though i have explicitly added the same jar file

\opt\mapr\hive\hive-1.2\lib\hive-jdbc-1.2.0-mapr-1603.jar

in my class path.I am getting this error.

 

Kindly help me with the same.

 

Thanks and Regards

Sanjeev Sukumaran

Outcomes