Support Questions
Find answers, ask questions, and share your expertise

,how to setup jdbc driver jars for a hive client - hdp 2.5?

,how to setup jdbc driver jars for a hive client - hdp 2.5?

New Contributor

,

Tried adding all possible jars ( hive-jdbc,hive-service,hadoop-common, hadoop-auth, log4j,slf4j etc) but getting the following exception :

but when use the jdbc-uber jar from here: https://community.hortonworks.com/repos/33592/hive-jdbc-uber-jar.html

it works fine.trying to use the standard jars.any suggestions would be appreciated.

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Menlo} span.s1 {font-variant-ligatures: no-common-ligatures} span.Apple-tab-span {white-space:pre}

Reported exception:

javax.xml.parsers.FactoryConfigurationError: Provider for class javax.xml.parsers.SAXParserFactory cannot be created

at javax.xml.parsers.FactoryFinder.findServiceProvider(FactoryFinder.java:311)

at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:267)

at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:127)

at ch.qos.logback.core.joran.event.SaxEventRecorder.buildSaxParser(SaxEventRecorder.java:81)

at ch.qos.logback.core.joran.event.SaxEventRecorder.recordEvents(SaxEventRecorder.java:59)

at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:134)

at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:99)

at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:49)

at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)

at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)

at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)

at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)

at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)

at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)

at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)

at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)

at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)

at org.apache.activemq.jms.pool.PooledConnectionFactory.<clinit>(PooledConnectionFactory.java:68)

Caused by: java.util.ServiceConfigurationError: javax.xml.parsers.SAXParserFactory: Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not found

at java.util.ServiceLoader.fail(ServiceLoader.java:239)

at java.util.ServiceLoader.access$300(ServiceLoader.java:185)

at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:372)

at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)

at java.util.ServiceLoader$1.next(ServiceLoader.java:480)

at javax.xml.parsers.FactoryFinder$1.run(FactoryFinder.java:294)

at java.security.AccessController.doPrivileged(Native Method)

at javax.xml.parsers.FactoryFinder.findServiceProvider(FactoryFinder.java:289)

... 26 more

5 REPLIES 5

Re: ,how to setup jdbc driver jars for a hive client - hdp 2.5?

Expert Contributor

Please try to add the below jar :

/usr/hdp/<hdp-version>/hadoop/client/xercesImpl.jar

[root@ambari-slave1 ~]# find /usr/hdp -name xercesImpl.jar
/usr/hdp/2.5.3.0-37/hadoop/client/xercesImpl.jar
[root@ambari-slave1 ~]# /usr/jdk64/jdk1.8.0_77/bin/jar -tvf /usr/hdp/2.5.3.0-37/hadoop/client/xercesImpl.jar | grep -i SAXParserFactoryImp
  2701 Fri Sep 14 18:26:18 UTC 2007 org/apache/xerces/jaxp/SAXParserFactoryImpl.class
[root@ambari-slave1 ~]#

Re: ,how to setup jdbc driver jars for a hive client - hdp 2.5?

Guru
@Mohit Nagrath

If you are trying to write a simple client, then these jars should be enough for you to work with:

Here is a simple JDBC client app that describes a table.

import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
 
public class myClient {
  private static String driverName = "org.apache.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);
    }
    //replace "hive" here with the name of the user the queries should run as
    Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "hive", "");
    Statement stmt = con.createStatement();
    String tableName = "testHiveDriverTable";
    stmt.execute("drop table if exists " + tableName);
    stmt.execute("create table " + tableName + " (key int, value string)");
    // show tables
    String sql = "show tables '" + tableName + "'";
    System.out.println("Running: " + sql);
    ResultSet 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));
    }
   }
  }  
    


Compiled using the following jars:

javac -cp /usr/hdp/2.5.0.0-1245/hadoop/hadoop-common-2.7.3.2.5.0.0-1245.jar:/usr/hdp/2.5.0.0-1245/hive/lib/hive-common-1.2.1000.2.5.0.0-1245.jar:/usr/hdp/2.5.0.0-1245/hive/lib/hive-jdbc-1.2.1000.2.5.0.0-1245-standalone.jar:.  myClient.java

Executed using the same jars:

java -cp /usr/hdp/2.5.0.0-1245/hadoop/hadoop-common-2.7.3.2.5.0.0-1245.jar:/usr/hdp/2.5.0.0-1245/hive/lib/hive-common-1.2.1000.2.5.0.0-1245.jar:/usr/hdp/2.5.0.0-1245/hive/lib/hive-jdbc-1.2.1000.2.5.0.0-1245-standalone.jar:.  myClient
Dec 29, 2016 9:40:29 PM org.apache.hive.jdbc.Utils parseURL
INFO: Supplied authorities: localhost:10000
Dec 29, 2016 9:40:29 PM org.apache.hive.jdbc.Utils parseURL
INFO: Resolved authority: localhost:10000
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Running: show tables 'testHiveDriverTable'
testhivedrivertable
Running: describe testHiveDriverTable
key	int
value	string

Re: ,how to setup jdbc driver jars for a hive client - hdp 2.5?

Explorer

I am using HDP 2.3

I am able to fetch data from hive to resultSet through JDBC

javac -cp /usr/hdp/2.3.4.7-4/hadoop/hadoop-common-2.7.1.2.3.4.7-4.jar:/usr/hdp/2.3.4.7-4/hive/lib/hive-common-1.2.1.2.3.4.7-4.jar:/usr/hdp/2.3.4.7-4/hive/lib/hive-jdbc-1.2.1.2.3.4.7-4-standalone.jar:.  hive_connection.java 
java -cp /usr/hdp/2.3.4.7-4/hadoop/hadoop-common-2.7.1.2.3.4.7-4.jar:/usr/hdp/2.3.4.7-4/hive/lib/hive-common-1.2.1.2.3.4.7-4.jar:/usr/hdp/2.3.4.7-4/hive/lib/hive-jdbc-1.2.1.2.3.4.7-4-standalone.jar:.  hive_connection

but problem is in delete and update :

Caused by: org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: SemanticException [Error 10294]: Attempt to do update or delete using transaction manager that does not support these operations.

table is ORC and i am able to delete data through hive shell but through java jdbc it showing above error

delete from mpm_txt_ppp_xxx_history_orc_del where kmmrercd=10001204

Re: ,how to setup jdbc driver jars for a hive client - hdp 2.5?

New Contributor

Thanks for your response.There is a small issue that is seen with the simple jdbc client. when i run the count query on a hive table using my jdbc client i am seeing different numbers being returned vs when i am running the same count query from hive-cli or other means.Any such known issues that have been seen before?

Re: ,how to setup jdbc driver jars for a hive client - hdp 2.5?

Guru

There should be no difference in either outputs. Can you share the query ?